So I want to migrate from Spyder to VSCode, and I come across this problem where I cannot access a dataset as my working directory is not the same as the dataset’s path.
launch.json
is not auto-generated for me as I’m not debugging anything (I tried this).
How do I set the working directory to always be the dir of the Python file I want to run, in VSCode? (and if it’s bad practice, could you show me a config that is easy to work with?) I’d like to set this up for VSCode’s IPython terminal.
Advertisement
Answer
Updated Solution: working as of 21/1/2021
Option 1:
- Locate and open the user settings file:
- Windows
%APPDATA%CodeUsersettings.json
- macOS
$HOME/Library/Application Support/Code/User/settings.json
- Linux
$HOME/.config/Code/User/settings.json
- Windows
- Add this line:
"python.terminal.executeInFileDir": true
Option 2:
- Open the Settings editor:
- On Windows/Linux – File > Preferences > Settings
- On macOS – Code > Preferences > Settings
- or use the keyboard shortcut
(Ctrl+,)
.
- Check the following box:
- Extensions > Python > Terminal: Execute In File Dir.
- or use the Search bar and type this setting id
python.terminal.executeInFileDir
.