[英]Setting the Python path for local project in VS Code without using the settings.json file
This answer from a Visual Studio Code developer says that it is reasonable to keep a Visual Studio Code project's settings.json
file in a project's git repository to enforce code standards across different development environments.这个来自 Visual Studio Code 开发人员的回答说,将 Visual Studio Code 项目的settings.json
文件保留在项目的 git 存储库中以在不同的开发环境中强制执行代码标准是合理的。 One down-side though is that when I select the Python interpreter path at the bottom of the screen (so the linter can find the installed packages), the following entry gets added to the settings.json
file:但一个缺点是,当我选择屏幕底部的 Python 解释器路径(以便 linter 可以找到已安装的包)时,以下条目将添加到settings.json
文件中:
"python.pythonPath": "/path/to/conda/envs/my-env-name/bin/python",
This path is local to the machine and assumes that conda is being used.此路径是机器的本地路径,并假定正在使用 conda。 I have to avoid adding this setting to the settings.json
that I commit to the git repository, which is annoying.我必须避免将此设置添加到我提交给 git 存储库的settings.json
中,这很烦人。
Is there a way to set the Python path locally for a project without writing a setting into the settings.json
file?有没有办法在不将设置写入settings.json
文件的情况下为项目在本地设置 Python 路径?
目前不直接支持它,但我们有一个功能请求,如果您想优先查看它,您可以投票。
One workaround would be to:一种解决方法是:
settings.json
从本地工作区settings.json
删除该行settings.json
将其复制粘贴到您的 User settings.json
See " VSCode User and Workspace Settings ".请参阅“ VSCode 用户和工作区设置”。
That way, your Git codebase can keep a generic settings.json
without local path.这样,您的 Git 代码库可以保留没有本地路径的通用settings.json
。
Since this would work for only one project, you can instead reference all your projects in severalMulti-root workspaces .由于这仅适用于一个项目,因此您可以在多个多根工作区中引用所有项目。
Then, regarding settings in that environment, you have three files:然后,关于该环境中的设置,您有三个文件:
That means you could switch workspaces, and in each multi-root workspace (each one composed of only one root), you would keep:这意味着您可以切换工作区,并且在每个多根工作区(每个工作区仅由一个根组成)中,您将保留:
pythonPath
path in user settings (applies to everything, everywhere)用户设置中的全局pythonPath
路径(适用于一切,无处不在)pythonPath
for a given multi-root workspace in the Workspace setting (outside of the project folder which is the only root for that "multi-root" workspace) Workspace 设置中给定多根工作区的特定pythonPath
(在项目文件夹之外,它是该“多根”工作区的唯一根目录)settings.json
project-specific settings in the project folder (which is the only root of the workspace)项目文件夹中的公共版本化settings.json
项目特定设置(这是工作区的唯一根目录)Again, by switching workspace, you can differentiate between:同样,通过切换工作区,您可以区分:
pythonPath
特定于工作区的私有设置,位于您的计算机本地,如pythonPath
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.