'VS Code - Open Terminal in Current Directory
I am trying to run python code inside Vs code, when I click "Run Python File" Option from top right (play icon). It shows "FileNotFoundError: [Errno 2] No such file or directory: 'jpgs'"
Upon using "pwd" command in same terminal, it shows It's in "/Users/arsh" Directory instead of my python project directory. I have to cd to that folder and run the button to make it working.
Is there any way in VS code to run the python file from current folder automatically? So every time I don't need to tell terminal to goto project folder then run "Run python code" command from VS Code.
Solution 1:[1]
Open the project folder in VS Code using File -> Open Folder.... This will make the shell always start in that folder. You can then re-open your Python file from within that new workspace.
Solution 2:[2]
I think VS Code will often run scripts in the Python install location. You can change this.
Click the gear icon on the bottom left of VS Code.

Then click settings.
A search bar will come up. Type in "Execute in File Path" and click the checkmark or set that to true.
Reload Visual Studio Code and you shouldn't have to open Visual Studio Code in the folder each time you want to run a script without specifying the absolute file path.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | carlfriedrich |
| Solution 2 | Jeremy Caney |
