How to correctly set PYTHONPATH for Visual Studio Code

后端 未结 5 793
执念已碎
执念已碎 2020-12-23 12:53

How do I correctly set up the $PYTHONPATH variable for my workspace in VisualStudio Code?

Background Information

I have install

5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-23 13:45

    Setting PYTHONPATH in .env works for me. Note that the effect just is for vscode and the tools it runs, such as pylint.

    My situation: I have a project that is not a pip installable package, but simply a source folder. (For historical reasons...)

    myproject/src

    The project has dependencies defined in a pip requires file.

    My setup:

    1. I create a virtualenv, and install the packages from the requires file.
    2. I open vscode in the folder myproject - so this becomes the root of the vscode "project".
    3. I point vscode to use the virtualenv as the python interpreter. This will make imports of dependencies installed with pip work. (For linters, intellisense, etc)
    4. To also make imports from my project source work for the linters (pylint especially) in vscode, I add a .env with this content, adding my project source folder to the PYTHONPATH:
    PYTHONPATH=./src:${PYTHONPATH}
    

提交回复
热议问题