Skip to content

New Integrated Terminal doesn't activate defined virtual environment for workspace #17827

Closed

Description

Environment data

  • VS Code version: 1.61.0
  • Extension version (available under the Extensions sidebar): v2021.10.1365161279 (installed from VSIX as it is not yet available through the extensions marketplace)
  • OS and version: Arch Linux with Kernel 5.14
  • Python version (& distribution if applicable, e.g. Anaconda): 3.9
  • Type of virtual environment used (N/A | venv | virtualenv | conda | ...): poetry

Expected behaviour

When creating a new terminal in a multi-root workspace, the correct workspace folders' virtual environment is automatically activated for the chosen workspace directory (regardless of open/active files). This should have apparently been fixed by #17595.

Actual behaviour

  • if there are no open files, no virtual environment is activated
  • if there is an opened file belonging to a python project, then the virtual environment of that workspace folder is activated, irrespective of the chose workspace directory

The extension output also shows an error and suggests using the --enable-proposed-api ms-python.python switch, which eliminates said error but other than that results in the same behaviour.

Steps to reproduce:

  1. create two project directories test1 and test2
  2. initialize poetry in both directories with poetry init
  3. in both project directories create .vscode/settings.json which sets the python.pythonPath (random name generated by poetry), similar to the following:
test1/.vscode/settings.json:
{
    "python.pythonPath": "/home/user/.cache/pypoetry/virtualenvs/test1-ThPNazQP-py3.9/bin/python"
}

test2/.vscode/settings.json:
{
    "python.pythonPath": "/home/user/.cache/pypoetry/virtualenvs/test2-Dk1LSx4W-py3.9/bin/python"
}
  1. play around with the above mentioned scenarios of (no) opened files while creating a New Terminal and selecting a working directory.

Logs

Output for Python in the Output panel (View→Output, change the drop-down the upper-right of the Output panel to Python)

No command line switch:

Error 2021-10-21 13:17:02: Failed to activate a workspace, Class name = y, completed in 448ms, has a falsy return value, Arg 1: <Uri:/home/user/workspace/vs-code-venv/test1>, Return Value: undefined [Error: [ms-python.python]: Proposed API is only available when running out of dev or with the following command line switch: --enable-proposed-api ms-python.python
        at D (/usr/lib/code/out/vs/workbench/services/extensions/node/extensionHostProcess.js:94:81006)
        at v (/usr/lib/code/out/vs/workbench/services/extensions/node/extensionHostProcess.js:94:80953)
        at Object.get testResults [as testResults] (/usr/lib/code/out/vs/workbench/services/extensions/node/extensionHostProcess.js:103:23607)
        at P.activate (/home/user/.vscode-oss/extensions/ms-python.python-2021.10.1365161279/out/client/extension.js:59:75328)
        at /home/user/.vscode-oss/extensions/ms-python.python-2021.10.1365161279/out/client/extension.js:52:193572
        at Array.map (<anonymous>)
        at y.activateWorkspace (/home/user/.vscode-oss/extensions/ms-python.python-2021.10.1365161279/out/client/extension.js:52:193563)]
Error 2021-10-21 13:17:02: Failure during activation. [Error: [ms-python.python]: Proposed API is only available when running out of dev or with the following command line switch: --enable-proposed-api ms-python.python
        at D (/usr/lib/code/out/vs/workbench/services/extensions/node/extensionHostProcess.js:94:81006)
        at v (/usr/lib/code/out/vs/workbench/services/extensions/node/extensionHostProcess.js:94:80953)
        at Object.get testResults [as testResults] (/usr/lib/code/out/vs/workbench/services/extensions/node/extensionHostProcess.js:103:23607)
        at P.activate (/home/user/.vscode-oss/extensions/ms-python.python-2021.10.1365161279/out/client/extension.js:59:75328)
        at /home/user/.vscode-oss/extensions/ms-python.python-2021.10.1365161279/out/client/extension.js:52:193572
        at Array.map (<anonymous>)
        at y.activateWorkspace (/home/user/.vscode-oss/extensions/ms-python.python-2021.10.1365161279/out/client/extension.js:52:193563)]
Error 2021-10-21 13:17:02: sendStartupTelemetry() failed. [Error: [ms-python.python]: Proposed API is only available when running out of dev or with the following command line switch: --enable-proposed-api ms-python.python
        at D (/usr/lib/code/out/vs/workbench/services/extensions/node/extensionHostProcess.js:94:81006)
        at v (/usr/lib/code/out/vs/workbench/services/extensions/node/extensionHostProcess.js:94:80953)
        at Object.get testResults [as testResults] (/usr/lib/code/out/vs/workbench/services/extensions/node/extensionHostProcess.js:103:23607)
        at P.activate (/home/user/.vscode-oss/extensions/ms-python.python-2021.10.1365161279/out/client/extension.js:59:75328)
        at /home/user/.vscode-oss/extensions/ms-python.python-2021.10.1365161279/out/client/extension.js:52:193572
        at Array.map (<anonymous>)
        at y.activateWorkspace (/home/user/.vscode-oss/extensions/ms-python.python-2021.10.1365161279/out/client/extension.js:52:193563)]
Starting Jedi language server.

When using the proposed switch --enable-proposed-api ms-python.python:

> conda info --json
> "poetry env list --full-path"
cwd: ~/workspace/vs-code-venv/test1
> "poetry env list --full-path"
cwd: ~/workspace/vs-code-venv/test2
> ~/.cache/pypoetry/virtualenvs/test1-ThPNazQP-py3.9/bin/python ~/.vscode-oss/extensions/ms-python.python-2021.10.1365161279/pythonFiles/interpreterInfo.py
Python interpreter path: ~/.cache/pypoetry/virtualenvs/test1-ThPNazQP-py3.9/bin/python
> /bin/python ~/.vscode-oss/extensions/ms-python.python-2021.10.1365161279/pythonFiles/interpreterInfo.py
> /sbin/python ~/.vscode-oss/extensions/ms-python.python-2021.10.1365161279/pythonFiles/interpreterInfo.py
> /usr/bin/python ~/.vscode-oss/extensions/ms-python.python-2021.10.1365161279/pythonFiles/interpreterInfo.py
> /usr/sbin/python ~/.vscode-oss/extensions/ms-python.python-2021.10.1365161279/pythonFiles/interpreterInfo.py
> ~/.cache/pypoetry/virtualenvs/test2-Dk1LSx4W-py3.9/bin/python ~/.vscode-oss/extensions/ms-python.python-2021.10.1365161279/pythonFiles/interpreterInfo.py
Starting Jedi language server.
> conda --version

When opening/switching between files:

Python interpreter path: ~/.cache/pypoetry/virtualenvs/test2-Dk1LSx4W-py3.9/bin/python
Python interpreter path: ~/.cache/pypoetry/virtualenvs/test1-ThPNazQP-py3.9/bin/python

EDIT: typo

Activity

  1. added
    bugIssue identified by VS Code Team member as probable bug
    triage-neededNeeds assignment to the proper sub-team
    on Oct 21, 2021
  2. kimadeline commented on Oct 21, 2021

    @kimadeline

    Hi @lluetcke-ct,

    Which VSIX did you install? Can you try switching to the Insiders version of the Python instead?

  3. toastedonion commented on Oct 22, 2021

    @toastedonion
    Author

    I installed the VSIX from the releases: https://github.com/microsoft/vscode-python/releases/download/2021.10.1365161279/ms-python-release.vsix

    Can you try switching to the Insiders version of the Python instead?

    Thanks, I tried it and the daily as well as the weekly insiders channel are working for me.

  4. kimadeline commented on Oct 22, 2021

    @kimadeline

    Sounds good. The change introduced by #17595 will be released as part of the 2021.11 release, closing.

  5. locked as resolved and limited conversation to collaborators on Nov 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

area-environmentsFeatures relating to handling interpreter environmentsbugIssue identified by VS Code Team member as probable buginfo-neededIssue requires more information from poster

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions