![]() |
How to fix error code 2 in python, “directory not found”? - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: How to fix error code 2 in python, “directory not found”? (/thread-17247.html) |
How to fix error code 2 in python, “directory not found”? - dav3javu - Apr-03-2019 I'm setting up a keylogger for my mac OS to track esports reaction times. Most of the code is fine, with pynput installed successfully and the code seeming to check out, however when I go to run the code in Visual studio code (my text editor) i get the error: 'can't open file '.logger.pyw': [Errno 2] No such file or directory' can anyone help me with this? i'm quite new to python so i'm sure its a simple fix i've not done! My python code is: from pynput.keyboard import Key, Listener #vanilla import logging #make a log file log_dir = "" logging.basicConfig(filename=(log_dir + "key_log.txt"), level=logging.DEBUG, format='%(asctime)s: %(message)s:') def on_press(key): logging.info(str(key)) #if key == Key.esc: #stop listener #return false with Listener(on_press=on_press) as listener: listener.join()And my terminal is: PS /Users/dav3javu/Desktop/keylogger/pynput-master> python3 .logger.pyw /Library/Frameworks/Python.framework/Versions/3.6/Resources/Python.app /Contents/MacOS/Python: can't open file '.logger.pyw': [Errno 2] No such file or directory RE: How to fix error code 2 in python, “directory not found”? - Larz60+ - Apr-03-2019 Quote:'can't open file '.logger.pyw': [Errno 2] No such file or directory'Always post complete, unaltered error traceback, inside of BBCode error tags. It contains valuable information that helps with debugging. log_dir is an empty string, so not needed at all. It also looks like the file is in the same directory as you python script. If so, add the following code (not tested): # replace line 8 with: os.chdir(os.path.abspath(os.path.dirname(__file__))) logging.basicConfig(filename='key_log.txt', level=logging.DEBUG, format='%(asctime)s: %(message)s:') # add after line 3 import osalso when running, use python3 .logger.py
|