Skip to content

Python virtual environment not correctly activated in terminal with uv and WSL #243225

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

Closed
diego-pm opened this issue Mar 11, 2025 · 5 comments
Closed
Assignees

Comments

@diego-pm
Copy link

diego-pm commented Mar 11, 2025

Type: Bug

I am developing with python in WSL2, and using uv to create the virtual environment. However, when opening the integrated terminal of vs code, the virtual environment does not get automatically activated correctly.

It seems that it is automatically activated because the name of the environment appears in the prompt, but I cannot access the executables (such as python). Also, the reported python version is the system python version, not the python version of the virtual environment.

on git develop via py v3.12.3 (.venv) 
> python
Command 'python' not found, did you mean:
  command 'python3' from deb python3
  command 'python' from deb python-is-python3

on git develop via py v3.12.3 (.venv) 
>

Image

I need to manually activate the environment running source ./.venv/bin/activate. Then, I can correctly execute python use the libraries in the virtual environment from the terminal.

on git develop via py v3.12.3 (.venv) 
> source ./.venv/bin/activate

on git develop via py v3.10.16 (.venv) 
> python
Python 3.10.16 (main, Feb 12 2025, 14:50:02) [Clang 19.1.6 ] on linux
Type "help", "copyright", "credits" or "license" for more information.
Ctrl click to launch VS Code Native REPL
>>> 

Image

VS Code version: Code 1.98.1 (2fc07b8, 2025-03-10T15:38:08.854Z)
OS version: Windows_NT x64 10.0.19045
Modes:
Remote OS version: Linux x64 5.15.167.4-microsoft-standard-WSL2

System Info
Item Value
CPUs Intel(R) Core(TM) Ultra 7 165U (14 x 2688)
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
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: enabled
webnn: disabled_off
Load (avg) undefined
Memory (System) 15.46GB (1.75GB free)
Process Argv --crash-reporter-id 74d13807-d8a0-4836-95d0-b6a8d2261209
Screen Reader no
VM 0%
Item Value
Remote WSL: Ubuntu
OS Linux x64 5.15.167.4-microsoft-standard-WSL2
CPUs Intel(R) Core(TM) Ultra 7 165U (14 x 0)
Memory (System) 7.49GB (4.88GB free)
VM 0%
Extensions (36)
Extension Author (truncated) Version
markdown-mermaid bie 1.27.0
ruff cha 2025.14.0
path-intellisense chr 2.10.0
copilot Git 1.282.0
copilot-chat Git 0.25.0
vscode-pull-request-github Git 0.106.0
rainbow-csv mec 3.18.0
git-graph mhu 1.30.0
debugpy ms- 2025.4.1
python ms- 2025.2.0
vscode-pylance ms- 2025.3.1
datawrangler ms- 1.20.1
jupyter ms- 2025.2.0
jupyter-keymap ms- 1.1.2
jupyter-renderers ms- 1.1.0
vscode-jupyter-cell-tags ms- 0.1.9
vscode-jupyter-slideshow ms- 0.1.6
color-highlight nau 2.8.0
vscode-conventional-commits viv 1.26.0
better-comments aar 3.0.2
vscode-kmonad can 0.2.0
vscode-lark dir 0.1.0
dotenv mik 1.0.1
jupyter-keymap ms- 1.1.2
remote-containers ms- 0.401.0
remote-ssh ms- 0.118.0
remote-ssh-edit ms- 0.87.0
remote-wsl ms- 0.88.5
vscode-remote-extensionpack ms- 0.26.0
remote-explorer ms- 0.4.3
remote-server ms- 1.5.2
material-icon-theme PKi 5.20.0
rewrap stk 1.16.3
pdf tom 1.2.2
errorlens use 3.24.0
material-theme zhu 3.19.0

(1 theme extensions excluded)

A/B Experiments
vsliv368cf:30146710
vspor879:30202332
vspor708:30202333
vspor363:30204092
vswsl492:30256859
pythonvspyt551cf:31249601
vscod805cf:30301675
binariesv615:30325510
py29gd2263:31024239
c4g48928:30535728
azure-dev_surveyone:30548225
962ge761:30959799
f8hc8238:30694864
2e7ec940:31000449
pythontbext0:30879054
cppperfnew:31000557
dwnewjupytercf:31046870
nativerepl2:31139839
pythonrstrctxt:31112756
nativeloc2:31192216
iacca1:31171482
5fd0e150:31155592
dwcopilot:31170013
6074i472:31201624
dwoutputs:31242946
customenabled:31248079
hdaa2157:31222309
copilot_t_ci:31222730
f5992895:31254866
jda6j935:31233686
fh1c7952:31256801
31787653:31256342

@karthiknadig
Copy link
Member

Try the workarounds recommended here: microsoft/vscode-python#24699 (comment)

@diego-pm
Copy link
Author

I tried the first option ("python.experiments.optOutFrom": ["pythonTerminalEnvVarActivation"]) and it worked. Then, I removed the setting again and tried the second option (executing the command Python: clear cache and reload window) and it also works. So clearing the cache seems to have permanently fixed the issue without having to opt out from the experiment. Thanks!

@karthiknadig
Copy link
Member

@diego-pm Thanks for letting us know.

@karthiknadig karthiknadig closed this as not planned Won't fix, can't repro, duplicate, stale Mar 12, 2025
@Dynamith
Copy link

Dynamith commented Mar 25, 2025

@karthiknadig I also found this bug and found the following phenomenon.
When applying multiple environment changes to the Integrated terminal, only the last Path change is retained.
The python extension package contains 2 environment path changes from ms-python.python and ms-python.debugpy.
By enabling the extensions in a different order, I found that the order of these two can also be changed in the Environment Changes page.
Then printing the terminal variable $env:Path, I found that only the path changed by the later extension is retained.
Could it be fixed?

@karthiknadig
Copy link
Member

@Dynamith I am working on a fix for activations in the https://github.com/microsoft/vscode-python-environments extension. That extension supports uv for env creation, and package management. One thing we are looking into is to use activation mechanisms that doesn't involve us modifying the PATH from the extension. A issue that occurs with that approach is that the order of extension activation matters and can conflict as you have seen.

A work around for the above case is to add this to your user settings:

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

That will cause the extension to send the command to the terminal for activation.

@vs-code-engineering vs-code-engineering bot locked and limited conversation to collaborators Apr 26, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants