Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrated Terminal Not Successfully Activating pyenv-virtualenv #24701

Closed
rrigato opened this issue Dec 28, 2024 · 9 comments
Closed

Integrated Terminal Not Successfully Activating pyenv-virtualenv #24701

rrigato opened this issue Dec 28, 2024 · 9 comments
Assignees
Labels
area-environments Features relating to handling interpreter environments bug Issue identified by VS Code Team member as probable bug needs spike Label for issues that need investigation before they can be worked on.

Comments

@rrigato
Copy link

rrigato commented Dec 28, 2024

Type: Bug

Downgrading extensions and disabling all extensions does not seem to make a difference when attempting to use a virtualenv with the integrated terminal.

steps to reproduce

  1. Install pyenv and pyenv-virtualenv plugin
brew install pyenv
brew install pyenv-virtualenv
  1. Create virtualenv
pyenv install 3.9
pyenv virtualenv 3.9 lexicon
  1. Select interpreter of virtualenv in vscode

Image

Image

  1. Open terminal and observe that the integrated terminal is using the system python instead of the selected virtualenv:

Image

python --version; which python

Image

  1. Note that manual activation sources the virtualenv
source ~/.pyenv/versions/3.9.21/envs/lexicon/bin/activate
python --version; which python 

Image

replicated bug with downgraded extensions:

Extension Author (truncated) Version
debugpy ms- 2024.12.0
python ms- 2024.20.0
vscode-pylance ms- 2024.11.3

version information from above bug

VS Code version: Code 1.96.2 (fabdb6a30b49f79a7aba0f2ad9df9b399473380f, 2024-12-19T10:22:47.216Z)
OS version: Darwin arm64 24.2.0
Modes:

System Info
Item Value
CPUs Apple M1 (8 x 2400)
GPU Status 2d_canvas: enabled
canvas_oop_rasterization: enabled_on
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_graphite: disabled_off
video_decode: enabled
video_encode: enabled
webgl: enabled
webgl2: enabled
webgpu: enabled
webnn: disabled_off
Load (avg) 4, 17, 11
Memory (System) 8.00GB (0.08GB free)
Process Argv --crash-reporter-id 2df22562-96a1-416e-a275-cdad1d9ae4c8
Screen Reader no
VM 0%
Enabled Extensions
Extension Author (truncated) Version
debugpy ms- 2024.14.0
python ms- 2024.22.1
vscode-pylance ms- 2024.12.1
A/B Experiments
vsliv368cf:30146710
vspor879:30202332
vspor708:30202333
vspor363:30204092
vscod805cf:30301675
binariesv615:30325510
vsaa593:30376534
py29gd2263:31024239
vscaac:30438847
c4g48928:30535728
azure-dev_surveyone:30548225
962ge761:30959799
pythonnoceb:30805159
pythonmypyd1:30879173
h48ei257:31000450
pythontbext0:30879054
cppperfnew:31000557
dsvsc020:30976470
pythonait:31006305
dsvsc021:30996838
dvdeprecation:31068756
dwnewjupyter:31046869
2f103344:31071589
nativerepl2:31139839
pythonrstrctxt:31112756
nativeloc2:31192216
cf971741:31144450
iacca1:31171482
notype1:31157159
5fd0e150:31155592
dwcopilot:31170013
stablechunks:31184530
6074i472:31201624

@meganrogge meganrogge assigned karthiknadig and unassigned meganrogge Jan 7, 2025
@karthiknadig karthiknadig transferred this issue from microsoft/vscode Jan 8, 2025
@karthiknadig karthiknadig added bug Issue identified by VS Code Team member as probable bug area-environments Features relating to handling interpreter environments labels Jan 8, 2025
@github-actions github-actions bot added the triage-needed Needs assignment to the proper sub-team label Jan 8, 2025
@karthiknadig karthiknadig added needs spike Label for issues that need investigation before they can be worked on. and removed triage-needed Needs assignment to the proper sub-team labels Jan 8, 2025
@karthiknadig
Copy link
Member

@rrigato Can you share the logs from Output > Python? That should have some clues as to why we are not activating.

@rrigato
Copy link
Author

rrigato commented Jan 8, 2025

@karthiknadig Thanks for looking into this!

Is the below the correct logs? I ran the Python: Show Output command:

2025-01-08 18:15:11.588 [info] Experiment 'pythonRecommendTensorboardExt' is active
2025-01-08 18:15:11.588 [info] Experiment 'pythonTerminalEnvVarActivation' is active
2025-01-08 18:15:11.588 [info] Experiment 'pythonTestAdapter' is active
2025-01-08 18:15:11.588 [warning] Dir "/Users/ryan/apps/architecture/.pixi/envs" is not watchable (directory does not exist)
2025-01-08 18:15:11.588 [warning] Dir "/Users/ryan/apps/burnday/.pixi/envs" is not watchable (directory does not exist)
2025-01-08 18:15:11.588 [warning] Dir "/Users/ryan/apps/rrigato/.pixi/envs" is not watchable (directory does not exist)
2025-01-08 18:15:11.588 [warning] Dir "/Users/ryan/apps/homepage/.pixi/envs" is not watchable (directory does not exist)
2025-01-08 18:15:11.588 [warning] Dir "/Users/ryan/apps/rewatch/.pixi/envs" is not watchable (directory does not exist)
2025-01-08 18:15:11.588 [warning] Dir "/Users/ryan/apps/ratingsapi/.pixi/envs" is not watchable (directory does not exist)
2025-01-08 18:15:11.588 [warning] Dir "/Users/ryan/apps/audio/.pixi/envs" is not watchable (directory does not exist)
2025-01-08 18:15:11.588 [warning] Dir "/Users/ryan/apps/containerpoc/.pixi/envs" is not watchable (directory does not exist)
2025-01-08 18:15:11.588 [warning] Dir "/Users/ryan/apps/lexicon/.pixi/envs" is not watchable (directory does not exist)
2025-01-08 18:15:11.588 [info] Python interpreter path: ./avenv/bin/python
2025-01-08 18:15:11.588 [info] > pyenv which python
2025-01-08 18:15:11.588 [info] cwd: ~/apps/architecture
2025-01-08 18:15:11.745 [info] > . ~/apps/architecture/avenv/bin/activate && echo 'e8b39361-0157-4923-80e1-22d70d46dee6' && python ~/.vscode/extensions/ms-python.python-2024.22.2-darwin-arm64/python_files/printEnvVariables.py
2025-01-08 18:15:11.745 [info] shell: zsh
2025-01-08 18:15:11.790 [info] > ~/.pyenv/versions/3.12.7/bin/python ~/.vscode/extensions/ms-python.python-2024.22.2-darwin-arm64/python_files/printEnvVariables.py
2025-01-08 18:15:11.790 [info] shell: zsh
2025-01-08 18:15:11.838 [info] Prepending environment variable PATH in collection with /Users/ryan/.vscode/extensions/ms-python.python-2024.22.2-darwin-arm64/python_files/deactivate/zsh:/Users/ryan/apps/architecture/avenv/bin: {"applyAtShellIntegration":true,"applyAtProcessCreation":true}
2025-01-08 18:15:11.838 [info] Setting environment variable VIRTUAL_ENV in collection to /Users/ryan/apps/architecture/avenv {"applyAtShellIntegration":true,"applyAtProcessCreation":true}
2025-01-08 18:15:11.838 [info] Prepending environment variable PS1 in collection with (avenv)  {"applyAtShellIntegration":true,"applyAtProcessCreation":false}
2025-01-08 18:15:11.838 [info] Setting environment variable VIRTUAL_ENV_PROMPT in collection to (avenv)  {"applyAtShellIntegration":true,"applyAtProcessCreation":true}
2025-01-08 18:15:11.838 [info] Send text to terminal: /Users/ryan/.pyenv/versions/3.12.7/bin/python /Users/ryan/.vscode/extensions/ms-python.python-2024.22.2-darwin-arm64/python_files/printEnvVariablesToFile.py /Users/ryan/.vscode/extensions/ms-python.python-2024.22.2-darwin-arm64/python_files/deactivate/zsh/envVars.txt
2025-01-08 18:15:12.676 [info] Starting Pylance language server.
2025-01-08 18:15:12.738 [info] > ~/.pyenv/versions/3.9.21/bin/python3.9 -I ~/.vscode/extensions/ms-python.python-2024.22.2-darwin-arm64/python_files/get_output_via_markers.py ~/.vscode/extensions/ms-python.python-2024.22.2-darwin-arm64/python_files/interpreterInfo.py

  • Here is the system information I ran the above with:
CPUs Apple M1 (8 x 2400)
GPU Status 2d_canvas: enabled canvas_oop_rasterization: enabled_on direct_rendering_display_compositor: disabled_off_ok gpu_compositing: enabled multiple_raster_threads: enabled_on opengl: enabled_on rasterization: enabled raw_draw: disabled_off_ok skia_graphite: disabled_off video_decode: enabled video_encode: enabled webgl: enabled webgl2: enabled webgpu: enabled webnn: disabled_off
Load (avg) 2, 2, 3
Memory (System) 8.00GB (0.33GB free)
Process Argv --crash-reporter-id 2df22562-96a1-416e-a275-cdad1d9ae4c8
Screen Reader no
VM 0%
Extension Author (truncated) Version
debugpy ms- 2024.14.0
python ms- 2024.22.2
vscode-pylance ms- 2024.12.1

@karthiknadig
Copy link
Member

The logs seem to suggest the selected environment is different from the one you showed in the screenshot. But, in any case try this:

Add the following to your User settings.json, and Reload VS Code:

    "python.experiments.optOutFrom": ["pythonTerminalEnvVarActivation"]

@bgarvit01
Copy link

bgarvit01 commented Jan 9, 2025

Logs from Output>Python my system, downgrading is also not helping
I am working on remote python code from another machine using Remote - SSH Extension as well

2025-01-09 06:02:20.228 [info] Native locator: Refresh started
2025-01-09 06:02:20.246 [error] Python Extension: interpreterManager.refresh l [Error]: Failed to resolve env "/usr/local/bin/python3"
    at ae (/home/garvit.bhateja/.vscode-server/extensions/ms-python.python-2024.20.0-linux-x64/out/client/extension.js:2:2049071)
    at oe (/home/garvit.bhateja/.vscode-server/extensions/ms-python.python-2024.20.0-linux-x64/out/client/extension.js:2:2047031)
    at Immediate.<anonymous> (/home/garvit.bhateja/.vscode-server/extensions/ms-python.python-2024.20.0-linux-x64/out/client/extension.js:2:2043325)
    at processImmediate (node:internal/timers:483:21) {
  code: -4,
  data: undefined
}
2025-01-09 06:02:20.338 [info] Native locator: Refresh finished in 410 ms
2025-01-09 06:02:20.532 [info] > pyenv which python
2025-01-09 06:02:20.532 [info] cwd: .
2025-01-09 06:02:20.876 [warning] Microvenv failed as it is using proposed API which is constantly changing l [Error]: Failed to resolve env "/usr/local/bin/python3"
    at ae (/home/garvit.bhateja/.vscode-server/extensions/ms-python.python-2024.20.0-linux-x64/out/client/extension.js:2:2049071)
    at oe (/home/garvit.bhateja/.vscode-server/extensions/ms-python.python-2024.20.0-linux-x64/out/client/extension.js:2:2047031)
    at Immediate.<anonymous> (/home/garvit.bhateja/.vscode-server/extensions/ms-python.python-2024.20.0-linux-x64/out/client/extension.js:2:2043325)
    at processImmediate (node:internal/timers:483:21) {
  code: -4,
  data: undefined
}
2025-01-09 06:02:20.877 [error] [
  'Failed to activate a workspace, Class name = v, completed in 657ms, has a falsy return value, Arg 1: <Uri:/home/garvit.bhateja/nutest-py3-tests>, Arg 2: {"started":1736402539906}, Return Value: undefined',
  l [Error]: Failed to resolve env "/usr/local/bin/python3"
      at ae (/home/garvit.bhateja/.vscode-server/extensions/ms-python.python-2024.20.0-linux-x64/out/client/extension.js:2:2049071)
      at oe (/home/garvit.bhateja/.vscode-server/extensions/ms-python.python-2024.20.0-linux-x64/out/client/extension.js:2:2047031)
      at Immediate.<anonymous> (/home/garvit.bhateja/.vscode-server/extensions/ms-python.python-2024.20.0-linux-x64/out/client/extension.js:2:2043325)
      at processImmediate (node:internal/timers:483:21) {
    code: -4,
    data: undefined
  }
]
2025-01-09 06:02:20.877 [error] Failure during activation. l [Error]: Failed to resolve env "/usr/local/bin/python3"
    at ae (/home/garvit.bhateja/.vscode-server/extensions/ms-python.python-2024.20.0-linux-x64/out/client/extension.js:2:2049071)
    at oe (/home/garvit.bhateja/.vscode-server/extensions/ms-python.python-2024.20.0-linux-x64/out/client/extension.js:2:2047031)
    at Immediate.<anonymous> (/home/garvit.bhateja/.vscode-server/extensions/ms-python.python-2024.20.0-linux-x64/out/client/extension.js:2:2043325)
    at processImmediate (node:internal/timers:483:21) {
  code: -4,
  data: undefined
}
2025-01-09 06:02:20.877 [error] sendStartupTelemetry() failed. l [Error]: Failed to resolve env "/usr/local/bin/python3"
    at ae (/home/garvit.bhateja/.vscode-server/extensions/ms-python.python-2024.20.0-linux-x64/out/client/extension.js:2:2049071)
    at oe (/home/garvit.bhateja/.vscode-server/extensions/ms-python.python-2024.20.0-linux-x64/out/client/extension.js:2:2047031)
    at Immediate.<anonymous> (/home/garvit.bhateja/.vscode-server/extensions/ms-python.python-2024.20.0-linux-x64/out/client/extension.js:2:2043325)
    at processImmediate (node:internal/timers:483:21) {
  code: -4,
  data: undefined
}

@karthiknadig
Copy link
Member

@bgarvit01 is /usr/local/bin/python3 a valid python on the machine? Can you check if some setting in the remote settings.json is set to using that python?

@bgarvit01
Copy link

bgarvit01 commented Jan 9, 2025

In remote-settings.json:

  "python.defaultInterpreterPath": "/usr/local/bin/python3",

But in Remote machine:

$ which python3
/bin/python3

Worked after removing the default interpreter path

@karthiknadig
Copy link
Member

You don’t need to set it. If you really need to set it, then use the one you want for the project. It does not matter if it is a venv or global.

You set it to force the extension to select the one you provided in that setting. Typically, the project selector can select the environment if it exists in the workspace directory.

@rrigato
Copy link
Author

rrigato commented Jan 9, 2025

Thanks @karthiknadig

Adding the following to my settings.json fixed the issue!!!

    "python.experiments.optOutFrom": ["pythonTerminalEnvVarActivation"]

Any other information needed from my side, do you think that is a long term fix?

@karthiknadig
Copy link
Member

We plan on removing that experiment so that should be it for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-environments Features relating to handling interpreter environments bug Issue identified by VS Code Team member as probable bug needs spike Label for issues that need investigation before they can be worked on.
Projects
None yet
Development

No branches or pull requests

4 participants