[英]VS Code PYTHONPATH for Windows and Linux
I need to set the PYTHONPATH for a project in Visual Studio Code.我需要在 Visual Studio Code 中为项目设置 PYTHONPATH。 I have an
.env
file specifying the PYTHONPATH.我有一个指定 PYTHONPATH 的
.env
文件。 However, since my path consists of a number of directories, I need to use the following on Windows:但是,由于我的路径由多个目录组成,因此我需要在 Windows 上使用以下内容:
PYTHONPATH=./dirA;./dirB;${PYTHONPATH}
But use colon as a separator on Linux但是在 Linux 上使用冒号作为分隔符
PYTHONPATH=./dirA:./dirB:${PYTHONPATH}
My .env
file is stored in the source repository, as I don't want every person working on the project to figure it out by themselves.我的
.env
文件存储在源存储库中,因为我不希望参与该项目的每个人都自己弄清楚。 I tried setting different env files for Linux and Windows, but setting python.envFile.windows
caused the Python extension to fail entirely.我尝试为 Linux 和 Windows 设置不同的 env 文件,但是设置
python.envFile.windows
导致 Python 扩展完全失败。
How can I set the Visual Studio Code PYTHONPATH once, in a way that works for developers in both Linux and Windows?如何以一种对 Linux 和 Windows 中的开发人员都适用的方式设置一次 Visual Studio Code PYTHONPATH?
There is no OS-specific support for specifying paths to different .env
files to specify unique PYTHONPATH
values.没有特定于操作系统的支持指定不同
.env
文件的路径以指定唯一的PYTHONPATH
值。 Please file a feature request at https://github.com/microsoft/vscode-python if you would like to see that implemented.如果您希望看到实现,请在https://github.com/microsoft/vscode-python提交功能请求。
Since you are using vscode, you might need to setup a launch.json
file for your project, with at least 2 configurations - one for windows and another for Linux (see the documentation here https://code.visualstudio.com/docs/editor/debugging#_launch-configurations )由于您使用的是 vscode,您可能需要为您的项目设置一个
launch.json
文件,至少有 2 个配置 - 一个用于 Windows,另一个用于 Linux(请参阅此处的文档https://code.visualstudio.com/docs/编辑器/调试#_launch-configurations )
You will need to set the environment
field in each configuration with the right value for PYTHONPATH
.您需要使用
PYTHONPATH
的正确值在每个配置中设置environment
字段。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.