6

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. 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.pythonPath": "/path/to/conda/envs/my-env-name/bin/python",

This path is local to the machine and assumes that conda is being used. I have to avoid adding this setting to the settings.json that I commit to the git repository, which is annoying.

Is there a way to set the Python path locally for a project without writing a setting into the settings.json file?

2 Answers 2

2

It currently isn't directly supported, but we have a feature request that you can upvote if you would like to see it prioritized.

Sign up to request clarification or add additional context in comments.

Comments

1

One workaround would be to:

  • remove that line from the local workspace settings.json
  • copy-paste it to your User settings.json

See "VSCode User and Workspace Settings".

That way, your Git codebase can keep a generic settings.json without local path.

Since this would work for only one project, you can instead reference all your projects in several Multi-root workspaces.

Then, regarding settings in that environment, you have three files:

  • Preferences: Open User Settings - Open your global User settings
  • references: Open Workspace Settings - Open the settings section of your Workspace file.
  • Preferences: Open Folder Settings - Open the settings for the active folder.

That means you could switch workspaces, and in each multi-root workspace (each one composed of only one root), you would keep:

  • the global pythonPath path in user settings (applies to everything, everywhere)
  • the specific 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)
  • the public versioned settings.json project-specific settings in the project folder (which is the only root of the workspace)

Again, by switching workspace, you can differentiate between:

  • workspace-specific private settings, local to your computer, like a pythonPath
  • project specific settings, in the project folder, that you can version and publish.

2 Comments

Thanks, good suggestion. I assume though that it's not possible to set this on a per-project basis, since it's in the shared user settings file? I have other conda environments for other projects.
@Sean Right! I didn't think of that. I propose a workaround, using multi-root workspaces. See my edited answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.