question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Activate selected directory's environment within a multi-root workspace with different environments

See original GitHub issue

Looked around for open issues related to my problem; I could only find #690 – which has been closed.

To summarize, I have several different projects mapped using [workspace name].code-workspace and in each there is a .vscode/ containing settings.json with:

{
    "python.pythonPath": "venv\\Scripts\\python.exe"
}

Environment data

  • VS Code version: 1.49.3
  • Extension version (available under the Extensions sidebar): N/A
  • OS and version: Windows 10.0.18362 Build 18362
  • Python version (& distribution if applicable, e.g. Anaconda): Python 3.8.5 64bit
  • Type of virtual environment used (N/A | venv | virtualenv | conda | …): venv
  • Relevant/affected Python packages and their versions: N/A
  • Relevant/affected Python-related VS Code extensions and their versions: N/A
  • Value of the python.languageServer setting: N/A

Expected behaviour

On integrated prompt launch activate project’s venv using its ./.vscode/settings.json.

Actual behaviour

Uses the first project’s venv.

Steps to reproduce:

See this comment for a really good example.

Reproducing my specific example:

  1. Set up multi-root workspace.
  2. Add venv to each folder in workspace using python -m venv venv from within the folder or pointing it to the root of the directory.
  3. Close all files but leave workspace open.
  4. ctrl+shift+" ` " to launch new terminal.
  5. Select a directory other than the first one (gif).

NOTE: as an update (I’ve been playing around). The expected behavior occurs by doing the following:

  1. Create the multiple-root workspace in vscode (1 & 2 from my specific example above).
  2. Open a file within the directory you intend to activate your environment automatically by launching the terminal.
  3. f1-> Terminal: Create New Terminal (In Active Workspace).

Logs

NOTE: could not figure out how to get the logs for the integrated terminal/workspace automation.

Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.

Try the new cross-platform PowerShell https://aka.ms/pscore6

PS D:\github\ortools-pyinteractive> & d:/github/solverstack/solverstack-crud/venv/Scripts/Activate.ps1
(venv) PS D:\github\ortools-pyinteractive> 

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:11
  • Comments:16 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
j-mcommented, May 24, 2022

Slight variation but didn’t seem worth making a new issue:

We use .vscode/settings.json for personal settings and .code-workspace’s settings for anything that should be shared, so { "python.pythonPath": "venv\\Scripts\\python.exe"} isn’t in settings.json. Which means we run into the same problem, there’s no way to define pythonPath per workspace folder in .code-workspace.

So, is it possible to add the ability to map python path per-workspace-folder? e.g.

    "python.pythonPath": {
      "${workspaceFolder:project1}": "${workspaceFolder:project1}/venv/Scripts/python.exe",
      "${workspaceFolder:project2}": "${workspaceFolder:project2}/venv/Scripts/python.exe",
      "${workspaceFolder:project3}": "${workspaceFolder:project3}/venv/Scripts/python.exe",
    },

Does pythonPath even exist any more?

2reactions
brettcannoncommented, Aug 18, 2022

It’s on our iteration plan to take a fresh look at our terminal story and the multi-root part will play into it. But beyond that there are no updates.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Multi-root Workspaces in Visual Studio Code
You can open and work on multiple project folders in Visual Studio Code with multi-root workspaces.
Read more >
multiple virtual env usage for different directories inside single ...
I have a project in which I use multiple python virtual environments. For each directory, I use one different virtual environment.
Read more >
Develop Azure Functions by using Visual Studio Code
Write your functions in various languages while taking advantage of the ... Choose the directory location for your project workspace and ...
Read more >
VS Code Workspaces with ESP32 and ESP8266 Projects
Any other folder opened in VS Code outside that workspace won't have the same settings. You can selectively enable or disable extensions for...
Read more >
Multi-root Workspaces in VSCode for AL Development
Well, the concept of “multi-root workspaces” is actually most simply explained by: opening multiple projects (workspaces) at the same time, to ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found