[Errno 2] No such file or directory (Python)
See original GitHub issueExpected behaviour
Run a program that reads a file stored in the same directory as the program.
Actual behaviour
VS Code is returning the following in the terminal:
Traceback (most recent call last):
File "/Filepath/10-1_learning_python.py", line 3, in <module>
with open(filename) as file_content:
FileNotFoundError: [Errno 2] No such file or directory: 'learning_python.txt'
Steps to reproduce:
I am trying to run a very simple Python program in VS Code. In the same subfolder I have the two following files:
- 10-1_learning_python.py
- learning_python.txt
This is the code in “10-1_learning_python.py”:
filename = 'learning_python.txt'
with open(filename) as file_content:
content = file_content.read()
print(content)
When running the code I get this error:
FileNotFoundError: [Errno 2] No such file or directory: ‘learning_python.txt’
This code works (using the very same directory and files) if I run it in other applications such as SublimeText.
Environment data
I am using macOS Catalina 10.15.5. My VS Code version is as follows:
Version: 1.45.1 Commit: 5763d909d5f12fe19f215cbfdd29a91c0fa9208a Date: 2020-05-14T08:33:47.663Z Electron: 7.2.4 Chrome: 78.0.3904.130 Node.js: 12.8.1 V8: 7.8.279.23-electron.0 OS: Darwin x64 19.5.0
Value of the
python.languageServer
setting:Microsoft
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:6 (3 by maintainers)
Top GitHub Comments
You might have to enable, “Execute in file dir”.
That did it! I did not know about this setting.
Thank you very much and sorry for the trouble…