use*_*631 1 python linux visual-studio-code
我从源代码安装了不同的 python 版本,并为它们创建了虚拟环境,并在每个项目的设置中设置了它们。操作系统 (SuSe Leap) 附带 python 3.6。
如何在 VS Code 中设置每个项目的 PYTHONPATH?,我不想修改通用路径。
在设置中设置虚拟环境后,可以使用 python 内置函数,但不会在正确的路径中查找第三方包。
我已经pythonPath在 python 环境中设置了解释器,但在包导入方面仍然存在一些问题,并且我没有找到 PYTHONPATH 的变量?
Ste*_*SFT 10
您可以通过三种方法进行配置PYTHONPATH:
1.terminal.integrated.env.*在settings.json文件中。例如:
"terminal.integrated.env.windows": {
"PYTHONPATH": "${workspaceFolder}"
}
Run Code Online (Sandbox Code Playgroud)
但它只影响通过终端路由的操作,例如调试。
使用终端设置时,PYTHONPATH 会影响用户在终端内运行的任何工具,以及扩展通过终端路由为用户执行的任何操作(例如调试)。但是,在这种情况下,当扩展执行不通过终端路由的操作(例如使用 linter 或格式化程序)时,此设置不会对模块查找产生影响。
2.PYTHONPATH在.env文件中配置:
默认情况下,Python 扩展在当前工作区文件夹中查找并加载名为 .env 的文件。该文件由用户设置中的默认条目“python.envFile”:“${workspaceFolder}/.env”标识。
但它不会影响终端中运行的操作。
When PYTHONPATH is set using an .env file, it will affect anything the extension does on your behalf and actions performed by the debugger, but it will not affect tools run in the terminal.
3.Configure the "env" entry in the launch.json file, such as:
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"envFile": "${workspaceFolder}/.env",
"env": {
"PYTHONPATH": "${workspaceFolder}"
}
}
Run Code Online (Sandbox Code Playgroud)
Obviously, It only affects the debugging actions.
| 归档时间: |
|
| 查看次数: |
11681 次 |
| 最近记录: |