30

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?

Harry Reeder
  • 411
  • 1
  • 5
  • 5
  • See this [SO article](https://stackoverflow.com/questions/32964920/should-i-commit-the-vscode-folder-to-source-control). – CrnaStena Mar 06 '17 at 17:32
  • 3
    @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) – Harry Reeder Mar 07 '17 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". – Anthony Brien Oct 06 '17 at 13:48
  • Is this still not possible? I see: "Profiles: Extend from Default Profile #156144" in the vscode repo. – Achyut Rastogi Aug 10 '23 at 07:55

2 Answers2

9

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.

Ben Creasy
  • 3,825
  • 4
  • 40
  • 50
3

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.

herrbischoff
  • 3,294
  • 1
  • 29
  • 50
  • That's good solution. For me it's sufficient and works optimal. Thx – Joey Aug 12 '18 at 08:16
  • 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. – fonini Sep 20 '21 at 15:06
  • What works for me is: `"python.pythonPath": "${workspaceRoot}/venv/bin/python"` (using the `venv` symlink as suggested in the answer). – fonini Sep 20 '21 at 15:21