Python in VSCode: Set working directory to python file's path everytime

时光总嘲笑我的痴心妄想 提交于 2019-12-02 22:44:47

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!