问题
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.
回答1:
You can find more details on the launch.json
setting file in the Visual Studio Code User Guide, included how to create one and what it means.
In short, you should be able to just create a launch.json
file a .vscode
subfolder of the directory you usually open with Open Worspace and paste the snippet provided by the other answer. If you find that it doesn't work, you can try changing the cwd
option going from this:
"cwd": "${fileDirname}"
to this
"cwd": ""
来源:https://stackoverflow.com/questions/56776521/python-in-vscode-set-working-directory-to-python-files-path-everytime