36

I am working on a Python project, and I want to define the path to where I store my virtualenv for the project.

I have linting settings in my .vscode/settings.json workspace settings. However, this is checked into my Git repository and is common across any collaborators on the project. Thus, I don't think it would make sense to reference where I personally keep my virtualenv for this project in the workspace settings.

As it is a project-specific virtualenv, it does not make sense to reference it in my user settings either.

Is there a way I can store my path to my virtualenv for this project?

4
  • See this SO article. Commented Mar 6, 2017 at 17:32
  • 4
    @CrnaStena I see the point about using EditorConfig however that's not quite the same - I want to configure VSCode specific settings, but some are relevant to the entire team (ie which linter to use) and some are relevant only to the user (ie the full path to where binaries are stored) Commented Mar 7, 2017 at 14:37
  • Have the same issue, where I want to share workspace specific settings with the team, however this prevents me from storing my user settings specific to that workspace, for example my "perforce.client". Commented Oct 6, 2017 at 13:48
  • Is this still not possible? I see: "Profiles: Extend from Default Profile #156144" in the vscode repo. Commented Aug 10, 2023 at 7:55

3 Answers 3

14

You can override .vscode/settings.json with settings in code-workspace.json, but more general and flexible overriding does not seem to be possible - I recommend voting for Add ability to extend from other settings files. If you commit both .vscode/settings.json and [name].code-workspace, then it seems like it'll be difficult for team members to customize their settings.

Nested settings in .vscode/settings.json seem to override [name].code-workspace settings, so you could try committing a workspace file. Some people also commit example files, e.g. settings.json.default and instruct team members to remove the .default extension.

I messed around with an example: example.code-workspace

{ "folders": [ { "path": "." }, { "path": "nested" } ], "settings": { "window.zoomLevel": 1, "editor.fontSize": 8 } } 

With nested containing .vscode/settings.json:

{ "window.zoomLevel": 2, "editor.fontSize": 16 } 

This works as you'd probably expect: the nested folder settings override the workspace settings, although window.zoomLevel became disabled with a tooltip message saying that it would only be applied if opened directly.

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

1 Comment

Is this still not possible? I see: "Profiles: Extend from Default Profile #156144" in the vscode repo.
4

This should be possible if you're keeping the virtualenv in the same folder as the project code itself. Then you can use the following setting in .vscode/settings.json:

"python.venvPath": "${workspaceRoot}/venv" 

Just exclude venv from your SCM and you're done.

If you prefer to keep the virtualenv elsewhere, this can be solved by symlinking the location to venv inside the workspace root.

3 Comments

That's good solution. For me it's sufficient and works optimal. Thx
I'm getting this error message: "This setting can only be applied in user settings in local window or in remote settings in remote window." and I don't even know what it means.
What works for me is: "python.pythonPath": "${workspaceRoot}/venv/bin/python" (using the venv symlink as suggested in the answer).
1

Having a .vscode/settings.local.json file as a counterpart to the .vscode/settings.json file which can be gitignored is the subject of open feature-request Local Workspace settings #40233. I suggest that you give that issue ticket a thumbs up to show support for it. You can also subscribe to it to get notified about discussion and progress. Please avoid making noisy comments there like ones that just consist of "+1" / "bump".

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.