Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Venv is not activated when a new zsh terminal is open #24982

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
giulianopicco opened this issue Apr 11, 2025 · 17 comments · Fixed by #24988
Closed

Venv is not activated when a new zsh terminal is open #24982

giulianopicco opened this issue Apr 11, 2025 · 17 comments · Fixed by #24988
Assignees
Labels
info-needed Issue requires more information from poster triage-needed Needs assignment to the proper sub-team

Comments

@giulianopicco
Copy link

Type: Bug

The current selected python virtual environment is not being activated when a new zsh terminal is opened

VS Code version: Code 1.99.1 (7c6fdfb0b8f2f675eb0b47f3d95eeca78962565b, 2025-04-04T15:58:59.624Z)
OS version: Darwin arm64 24.4.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) 19, 18, 16
Memory (System) 16.00GB (1.18GB free)
Process Argv --crash-reporter-id d38c409b-133d-4ade-82e3-c8d63bfe316f
Screen Reader no
VM 0%
Extensions (127)
Extension Author (truncated) Version
vscode-sqlite ale 0.14.1
laravel-blade-vscode ami 2.0.4
tsl-problem-matcher amo 0.6.2
vscode-django bat 1.15.0
github-markdown-preview bie 0.3.0
markdown-checkbox bie 0.4.0
markdown-emoji bie 0.3.1
markdown-footnotes bie 0.1.1
markdown-mermaid bie 1.27.0
markdown-preview-github-styles bie 2.1.0
markdown-yaml-preamble bie 0.1.0
vscode-tailwindcss bra 0.14.15
turbo-console-log Cha 2.14.0
npm-intellisense chr 1.4.5
codeium Cod 1.42.7
dart-code Dar 3.108.2
flutter Dar 3.108.0
vscode-markdownlint Dav 0.59.0
vscode-eslint dba 3.0.10
vscode-deno den 3.43.6
emulate Die 1.7.1
docker doc 0.4.7
es7-react-js-snippets dsz 4.4.3
gitlens eam 17.0.2
prettier-vscode esb 11.0.0
flow-for-vscode flo 3.1.0
auto-rename-tag for 0.1.10
vscode-mysql for 0.5.0
copilot Git 1.301.0
copilot-chat Git 0.26.3
copilot-labs Git 0.17.1121
go gol 0.46.1
geminicodeassist goo 2.30.3
todo-tree Gru 0.0.226
debug-visualizer hed 2.4.0
rest-client hum 0.25.1
output-colorizer IBM 0.1.2
easy-snippet inu 0.7.5
search-node-modules jas 1.3.0
vscode-peacock joh 4.2.2
react-native-snippet jun 0.5.6
rn-full-pack kel 1.1.0
vscode-gutter-preview kis 0.32.2
kite kit 0.147.0
i18n-ally lok 2.13.1
json-to-ts Mar 1.8.0
Kotlin mat 1.7.1
maxshortcuts Max 0.0.1
rainbow-csv mec 3.19.0
template-string-converter meg 0.6.1
vscode-language-babel mgm 0.0.40
git-graph mhu 1.30.0
inline-fold moa 0.2.6
mongodb-vscode mon 1.13.0
djlint mon 2025.0.0
vscode-docker ms- 1.29.5
vscode-language-pack-es MS- 1.99.2025040909
autopep8 ms- 2025.2.0
debugpy ms- 2025.6.0
isort ms- 2025.0.0
python ms- 2025.5.2025041001
vscode-pylance ms- 2025.4.1
jupyter ms- 2025.3.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
remote-containers ms- 0.409.0
cmake-tools ms- 1.20.53
cpptools ms- 1.24.5
cpptools-extension-pack ms- 1.3.1
extension-test-runner ms- 0.0.12
js-debug-nightly ms- 2025.4.817
makefile-tools ms- 0.12.17
remote-explorer ms- 0.4.3
remote-server ms- 1.5.2
vscode-react-native msj 1.13.0
sqltools mtx 0.28.4
sqltools-driver-pg mtx 0.5.5
color-highlight nau 2.8.0
indent-rainbow ode 8.3.1
laravel-blade one 1.37.0
laravel5-snippets one 1.19.1
htmx-tags oto 0.0.8
alpine-intellisense pcb 1.0.2
platformio-ide pla 3.3.4
polacode pnp 0.3.4
postman-for-vscode Pos 1.10.1
inline-html pus 0.3.10
sqlite-viewer qwt 0.10.5
vscode-thunder-client ran 2.34.3
vscode-rapidapi-client Rap 1.10.2
vscode-services rap 1.0.2
vscode-commons red 0.0.6
vscode-xml red 0.28.1
LiveServer rit 5.7.9
claude-dev sao 3.11.1
code-settings-sync Sha 3.4.3
toggle-boolean sil 0.10.0
alpinejs-syntax-highlight spe 1.0.1
autoimport ste 1.5.4
code-spell-checker str 4.0.45
svelte-vscode sve 109.5.3
react-native-ide swm 1.4.2
even-better-toml tam 0.21.2
vscode-djaneiro the 1.4.2
vsfire tob 1.4.1
es6-string-html Tob 2.17.0
pdf tom 1.2.2
cmake twx 0.0.17
hello-world-react-vite und 0.0.1
errorlens use 3.25.0
highlight-matching-tag vin 0.11.0
intellicode-api-usage-examples Vis 0.2.9
vscodeintellicode Vis 1.3.2
vscode-icons vsc 12.12.0
material-ui-snippets vsc 3.3.8
mui-snippets vsc 1.0.1
vim vsc 1.29.0
volar Vue 2.2.8
gitblame wad 11.1.2
console-ninja Wal 1.0.426
vscode-todo-highlight way 1.0.5
jinja who 0.0.8
glean wix 5.2.2
change-case wma 1.0.0
markdown-all-in-one yzh 3.6.3

(1 theme extensions excluded)

A/B Experiments
vsliv368:30146709
vspor879:30202332
vspor708:30202333
vspor363:30204092
vswsl492cf:30256860
vscod805cf:30301675
binariesv615:30325510
c4g48928:30535728
azure-dev_surveyone:30548225
962ge761:30959799
h48ei257:31000450
pythontbext0:30879054
cppperfnew:31000557
dwnewjupyter:31046869
pythonrstrctxt:31112756
nativeloc1:31192215
5fd0e150:31155592
dwcopilot:31170013
6074i472:31201624
dwoutputs:31242946
customenabled:31248079
9064b325:31222308
copilot_t_ci:31222730
e5gg6876:31282496
pythoneinst12:31262605
bgtreat:31268568
4gafe986:31271826
5b33h341:31253271
31787653:31262186
3e8i5726:31271747
996jf627:31283433
763bd867:31283000
747dc170:31275177
g20af354:31278749
aj953862:31281341

@curia-damiano
Copy link

+1 I have the same problem and I can add more information.

I work in a Python devcontainer, so all my setup is isolated from the pysical machine and is versioned it git.
The environment is configured, but not activated.
I have seen that if I do ">Python: Select Interpreter", if finds the configured environment as first choice. And then all new terminal window has the environment correctly activated.

I can provide a GitHub repo configured where the feature was working in the past and not anymore now.

@drakon
Copy link

drakon commented Apr 14, 2025

+1 here.

Maybe this is helpful as well:

I use conda and what happens for me is that it seems to activate the environment ("conda info" shows the active environment py39 correctly) but when I do "which python" it shows not the version inside the environment but as if it wasn't activated. When I do "conda deactivate && conda activate py39" it works as expected again.

It used to work last Friday as expected and I think VSCode was then automatically updated and seems to behave in this way since then.

@AreChen
Copy link

AreChen commented Apr 14, 2025

+1 It can be confirmed that in Windows 11 WSL and macOS, the conda environment in zsh is always base and cannot automatically activate the selected environment.

@karthiknadig karthiknadig transferred this issue from microsoft/vscode Apr 14, 2025
@github-actions github-actions bot added the triage-needed Needs assignment to the proper sub-team label Apr 14, 2025
@karthiknadig
Copy link
Member

Can you share the logs from Output > Python?

@github-actions github-actions bot added the info-needed Issue requires more information from poster label Apr 14, 2025
@giulianopicco
Copy link
Author

giulianopicco commented Apr 14, 2025

Output > Python:

2025-04-14 12:51:46.753 [info] Experiment 'pythonRecommendTensorboardExt' is active
2025-04-14 12:51:46.753 [info] Experiment 'pythonTerminalEnvVarActivation' is active
2025-04-14 12:51:46.753 [info] Native locator: Refresh started
2025-04-14 12:51:46.753 [info] > pyenv which python
2025-04-14 12:51:46.753 [info] cwd: .
2025-04-14 12:51:46.753 [info] Python interpreter path: ./.venv/bin/python
2025-04-14 12:51:46.753 [info] Conda environment manager found at: /Users/user/opt/anaconda3/bin/conda
2025-04-14 12:51:46.753 [info] Using conda: /Users/user/opt/anaconda3/bin/conda
2025-04-14 12:51:48.011 [info] > . ./.venv/bin/activate && echo 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' && python ~/.vscode/extensions/ms-python.python-2025.5.2025041001-darwin-arm64/python_files/printEnvVariables.py
2025-04-14 12:51:48.011 [info] shell: zsh
2025-04-14 12:51:48.024 [info] Native locator: Refresh finished in 2999 ms
2025-04-14 12:51:48.416 [info] > ~/.pyenv/versions/3.10.1/bin/python ~/.vscode/extensions/ms-python.python-2025.5.2025041001-darwin-arm64/python_files/printEnvVariables.py
2025-04-14 12:51:48.416 [info] shell: zsh
2025-04-14 12:51:48.692 [info] Setting environment variable GOOGLE_MAPS_API_KEY in collection to XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX {"applyAtShellIntegration":true,"applyAtProcessCreation":true}
2025-04-14 12:51:48.692 [info] Prepending environment variable PATH in collection with /Users/user/.vscode/extensions/ms-python.python-2025.5.2025041001-darwin-arm64/python_files/deactivate/zsh:/Users/user/Developer/django_projects/eagle_eye_logistics/.venv/bin: {"applyAtShellIntegration":true,"applyAtProcessCreation":true}
2025-04-14 12:51:48.693 [info] Setting environment variable VIRTUAL_ENV in collection to /Users/user/Developer/django_projects/eagle_eye_logistics/.venv {"applyAtShellIntegration":true,"applyAtProcessCreation":true}
2025-04-14 12:51:48.693 [info] Prepending environment variable PS1 in collection with (.venv) {"applyAtShellIntegration":true,"applyAtProcessCreation":false}
2025-04-14 12:51:48.693 [info] Setting environment variable VIRTUAL_ENV_PROMPT in collection to (.venv) {"applyAtShellIntegration":true,"applyAtProcessCreation":true}
2025-04-14 12:51:48.693 [info] Send text to terminal: /Library/Developer/CommandLineTools/usr/bin/python3 /Users/user/.vscode/extensions/ms-python.python-2025.5.2025041001-darwin-arm64/python_files/printEnvVariablesToFile.py /Users/user/.vscode/extensions/ms-python.python-2025.5.2025041001-darwin-arm64/python_files/deactivate/zsh/envVars.txt
2025-04-14 12:51:53.668 [info] Starting Pylance language server.
2025-04-14 12:53:21.759 [info] > ~/opt/anaconda3/bin/conda info --json
2025-04-14 12:59:02.187 [info] Experiment 'pythonRecommendTensorboardExt' is active
2025-04-14 12:59:02.188 [info] Experiment 'pythonTerminalEnvVarActivation' is active
2025-04-14 12:59:02.195 [info] Native locator: Refresh started
2025-04-14 12:59:02.212 [info] Native locator: Refresh started
2025-04-14 12:59:02.228 [info] > pyenv which python
2025-04-14 12:59:02.228 [info] cwd: .
2025-04-14 12:59:02.868 [info] Python interpreter path: ./.venv/bin/python
2025-04-14 12:59:02.896 [info] Conda environment manager found at: /Users/user/opt/anaconda3/bin/conda
2025-04-14 12:59:02.896 [info] Using conda: /Users/user/opt/anaconda3/bin/conda
2025-04-14 12:59:02.981 [info] Native locator: Refresh finished in 786 ms
2025-04-14 12:59:03.990 [warning] Shell integration may not be active, environment activated may be overridden by the shell.
2025-04-14 12:59:04.027 [info] > . ./.venv/bin/activate && echo 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' && python ~/.vscode/extensions/ms-python.python-2025.4.0-darwin-arm64/python_files/printEnvVariables.py
2025-04-14 12:59:04.027 [info] shell: zsh
2025-04-14 12:59:04.071 [info] > ~/.pyenv/versions/3.12.2/bin/python ~/.vscode/extensions/ms-python.python-2025.4.0-darwin-arm64/python_files/printEnvVariables.py
2025-04-14 12:59:04.071 [info] shell: zsh
2025-04-14 12:59:04.400 [info] Starting Pylance language server.
2025-04-14 12:59:05.138 [info] Setting environment variable GOOGLE_MAPS_API_KEY in collection to XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX {"applyAtShellIntegration":true,"applyAtProcessCreation":true}
2025-04-14 12:59:05.138 [info] Prepending environment variable PATH in collection with /Users/user/.vscode/extensions/ms-python.python-2025.4.0-darwin-arm64/python_files/deactivate/zsh:/Users/user/Developer/django_projects/eagle_eye_logistics/.venv/bin: {"applyAtShellIntegration":true,"applyAtProcessCreation":true}
2025-04-14 12:59:05.138 [info] Setting environment variable VIRTUAL_ENV in collection to /Users/user/Developer/django_projects/eagle_eye_logistics/.venv {"applyAtShellIntegration":true,"applyAtProcessCreation":true}
2025-04-14 12:59:05.138 [info] Prepending environment variable PS1 in collection with (.venv) {"applyAtShellIntegration":true,"applyAtProcessCreation":true}
2025-04-14 12:59:05.138 [info] Setting environment variable VIRTUAL_ENV_PROMPT in collection to (.venv) {"applyAtShellIntegration":true,"applyAtProcessCreation":true}
2025-04-14 12:59:06.145 [info] Send text to terminal: /Library/Developer/CommandLineTools/usr/bin/python3 /Users/user/.vscode/extensions/ms-python.python-2025.4.0-darwin-arm64/python_files/printEnvVariablesToFile.py /Users/user/.vscode/extensions/ms-python.python-2025.4.0-darwin-arm64/python_files/deactivate/zsh/envVars.txt
2025-04-14 13:00:05.879 [info] Native locator: Refresh started
2025-04-14 13:00:05.895 [info] Conda environment manager found at: /Users/user/opt/anaconda3/bin/conda
2025-04-14 13:00:05.895 [info] Conda set to: /Users/user/opt/anaconda3/bin/conda
2025-04-14 13:00:05.964 [info] Native locator: Refresh finished in 85 ms
2025-04-14 13:00:08.136 [info] Active interpreter [/Users/user/Developer/django_projects/eagle_eye_logistics]: /Users/user/Developer/django_projects/eagle_eye_logistics/.venv/bin/python
2025-04-14 13:00:08.136 [info] Discover tests for workspace name: eagle_eye_logistics - uri: /Users/user/Developer/django_projects/eagle_eye_logistics
2025-04-14 13:00:09.139 [info] Setting environment variable GOOGLE_MAPS_API_KEY in collection to XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX {"applyAtShellIntegration":true,"applyAtProcessCreation":true}
2025-04-14 13:00:09.139 [info] Prepending environment variable PATH in collection with /Users/user/.vscode/extensions/ms-python.python-2025.4.0-darwin-arm64/python_files/deactivate/zsh:/Users/user/Developer/django_projects/eagle_eye_logistics/.venv/bin: {"applyAtShellIntegration":true,"applyAtProcessCreation":true}
2025-04-14 13:00:09.139 [info] Setting environment variable VIRTUAL_ENV in collection to /Users/user/Developer/django_projects/eagle_eye_logistics/.venv {"applyAtShellIntegration":true,"applyAtProcessCreation":true}
2025-04-14 13:00:09.139 [info] Prepending environment variable PS1 in collection with (.venv) {"applyAtShellIntegration":true,"applyAtProcessCreation":true}
2025-04-14 13:00:09.139 [info] Setting environment variable VIRTUAL_ENV_PROMPT in collection to (.venv) {"applyAtShellIntegration":true,"applyAtProcessCreation":true}
2025-04-14 13:02:22.170 [info] Native locator: Refresh started
2025-04-14 13:02:22.188 [info] Conda environment manager found at: /Users/user/opt/anaconda3/bin/conda
2025-04-14 13:02:22.188 [info] Conda set to: /Users/user/opt/anaconda3/bin/conda
2025-04-14 13:02:22.240 [info] Native locator: Refresh finished in 71 ms
2025-04-14 13:02:40.650 [info] Experiment 'pythonRecommendTensorboardExt' is active
2025-04-14 13:02:40.650 [info] Experiment 'pythonTerminalEnvVarActivation' is active
2025-04-14 13:02:40.650 [info] Native locator: Refresh started
2025-04-14 13:02:40.650 [info] Native locator: Refresh started
2025-04-14 13:02:40.665 [info] Conda environment manager found at: /Users/user/opt/anaconda3/bin/conda
2025-04-14 13:02:40.665 [info] Using conda: /Users/user/opt/anaconda3/bin/conda
2025-04-14 13:02:40.667 [info] Python interpreter path: ./.venv/bin/python
2025-04-14 13:02:40.689 [info] > pyenv which python
2025-04-14 13:02:40.689 [info] cwd: .
2025-04-14 13:02:41.050 [info] Native locator: Refresh finished in 510 ms
2025-04-14 13:02:41.731 [warning] Shell integration may not be active, environment activated may be overridden by the shell.
2025-04-14 13:02:41.734 [info] > . ./.venv/bin/activate && echo 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' && python ~/.vscode/extensions/ms-python.python-2025.4.0-darwin-arm64/python_files/printEnvVariables.py
2025-04-14 13:02:41.734 [info] shell: zsh
2025-04-14 13:02:41.781 [info] > ~/.pyenv/versions/3.10.1/bin/python ~/.vscode/extensions/ms-python.python-2025.4.0-darwin-arm64/python_files/printEnvVariables.py
2025-04-14 13:02:41.781 [info] shell: zsh
2025-04-14 13:02:41.999 [info] Starting Pylance language server.
2025-04-14 13:02:42.841 [info] Setting environment variable GOOGLE_MAPS_API_KEY in collection to XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX {"applyAtShellIntegration":true,"applyAtProcessCreation":true}
2025-04-14 13:02:42.841 [info] Prepending environment variable PATH in collection with /Users/user/.vscode/extensions/ms-python.python-2025.4.0-darwin-arm64/python_files/deactivate/zsh:/Users/user/Developer/django_projects/eagle_eye_logistics/.venv/bin: {"applyAtShellIntegration":true,"applyAtProcessCreation":true}
2025-04-14 13:02:42.841 [info] Setting environment variable VIRTUAL_ENV in collection to /Users/user/Developer/django_projects/eagle_eye_logistics/.venv {"applyAtShellIntegration":true,"applyAtProcessCreation":true}
2025-04-14 13:02:42.841 [info] Prepending environment variable PS1 in collection with (.venv) {"applyAtShellIntegration":true,"applyAtProcessCreation":true}
2025-04-14 13:02:42.841 [info] Setting environment variable VIRTUAL_ENV_PROMPT in collection to (.venv) {"applyAtShellIntegration":true,"applyAtProcessCreation":true}
2025-04-14 13:02:43.844 [info] Send text to terminal: /Library/Developer/CommandLineTools/usr/bin/python3 /Users/user/.vscode/extensions/ms-python.python-2025.4.0-darwin-arm64/python_files/printEnvVariablesToFile.py /Users/user/.vscode/extensions/ms-python.python-2025.4.0-darwin-arm64/python_files/deactivate/zsh/envVars.txt
2025-04-14 13:07:27.937 [info] Experiment 'pythonRecommendTensorboardExt' is active
2025-04-14 13:07:27.937 [info] Experiment 'pythonTerminalEnvVarActivation' is active
2025-04-14 13:07:27.937 [info] Native locator: Refresh started
2025-04-14 13:07:28.013 [info] Conda environment manager found at: /Users/user/opt/anaconda3/bin/conda
2025-04-14 13:07:28.013 [info] Using conda: /Users/user/opt/anaconda3/bin/conda
2025-04-14 13:07:28.070 [info] Python interpreter path: ./.venv/bin/python
2025-04-14 13:07:28.081 [info] Native locator: Refresh finished in 813 ms
2025-04-14 13:07:30.959 [info] > pyenv which python
2025-04-14 13:07:30.959 [info] cwd: .
2025-04-14 13:07:33.977 [info] > . ./.venv/bin/activate && echo 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' && python ~/.vscode/extensions/ms-python.python-2025.5.2025041001-darwin-arm64/python_files/printEnvVariables.py
2025-04-14 13:07:33.977 [info] shell: zsh
2025-04-14 13:07:34.122 [info] > ~/.pyenv/versions/3.10.1/bin/python ~/.vscode/extensions/ms-python.python-2025.5.2025041001-darwin-arm64/python_files/printEnvVariables.py
2025-04-14 13:07:34.122 [info] shell: zsh
2025-04-14 13:07:34.428 [info] Setting environment variable GOOGLE_MAPS_API_KEY in collection to XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX {"applyAtShellIntegration":true,"applyAtProcessCreation":true}
2025-04-14 13:07:34.428 [info] Prepending environment variable PATH in collection with /Users/user/.vscode/extensions/ms-python.python-2025.5.2025041001-darwin-arm64/python_files/deactivate/zsh:/Users/user/Developer/django_projects/eagle_eye_logistics/.venv/bin: {"applyAtShellIntegration":true,"applyAtProcessCreation":true}
2025-04-14 13:07:34.428 [info] Setting environment variable VIRTUAL_ENV in collection to /Users/user/Developer/django_projects/eagle_eye_logistics/.venv {"applyAtShellIntegration":true,"applyAtProcessCreation":true}
2025-04-14 13:07:34.428 [info] Prepending environment variable PS1 in collection with (.venv) {"applyAtShellIntegration":true,"applyAtProcessCreation":false}
2025-04-14 13:07:34.428 [info] Setting environment variable VIRTUAL_ENV_PROMPT in collection to (.venv) {"applyAtShellIntegration":true,"applyAtProcessCreation":true}
2025-04-14 13:07:34.428 [info] Send text to terminal: /Library/Developer/CommandLineTools/usr/bin/python3 /Users/user/.vscode/extensions/ms-python.python-2025.5.2025041001-darwin-arm64/python_files/printEnvVariablesToFile.py /Users/user/.vscode/extensions/ms-python.python-2025.5.2025041001-darwin-arm64/python_files/deactivate/zsh/envVars.txt
2025-04-14 13:07:35.627 [info] Starting Pylance language server.
2025-04-14 13:07:43.211 [info] > ~/opt/anaconda3/bin/conda info --json

@github-actions github-actions bot removed the info-needed Issue requires more information from poster label Apr 14, 2025
@karthiknadig
Copy link
Member

@giulianopicco Try disabling the following experiment, by adding this setting to your User Settings then reload and see if it works better.

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

@github-actions github-actions bot added the info-needed Issue requires more information from poster label Apr 14, 2025
@giulianopicco
Copy link
Author

@karthiknadig Your solution worked perfectly—thanks for the quick and effective fix! 🙌

@github-actions github-actions bot removed the info-needed Issue requires more information from poster label Apr 14, 2025
@curia-damiano
Copy link

I have tried this settings, both adding it to the .vscode/settings.json and to the devcontainer.json file.
In both cases it doesn't work to me.
I would like to reopen this issue, but I don't have the rights to do so.

@giulianopicco giulianopicco reopened this Apr 15, 2025
@DanielQu9
Copy link

DanielQu9 commented Apr 16, 2025

@giulianopicco Try disabling the following experiment, by adding this setting to your User Settings then reload and see if it works better.嘗試禁用以下實驗,方法是將此設置添加到您的 **User Settings(用戶設置 **),然後重新載入並查看它是否效果更好。

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

It works for me, thanks.👍

@curia-damiano
Copy link

curia-damiano commented Apr 16, 2025 via email

@drakon
Copy link

drakon commented Apr 16, 2025

@giulianopicco Try disabling the following experiment, by adding this setting to your User Settings then reload and see if it works better.

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

This worked for me as well. I believe it looks a bit different when it activates in the terminal than before (it shows the command twice; I think it used to do that in the past as well though). But it works again the same way.

@curia-damiano
Copy link

curia-damiano commented Apr 16, 2025 via email

@igadmile
Copy link

I had the same issue. The extension did not add $VIRTUAL_ENV/bin to the PATH env variable so the venv was not activated

@DanielQu9
Copy link

I have set it up, even in the global user settings, and not inside the dev
container.
Still when opening a new terminal, the virtual environment doesn't get
activated...

That's too bad.
I work on an M3 Mac
My symptom is that when it is first turned on, $VIRTUAL_ENV is written to the path, but $PATH is not introduced
After opening a new terminal, $PATH is introduced, but it will be at the end
Using where python3 will get the default path, while the expected behavior should be the venv path.
(Translated from Google)

@karthiknadig
Copy link
Member

For remote and dev container cases you need to put the setting in the remote machine global settings. When you bring up the settings UI you should be able to see 3 setting levels User, remote, and workspace. After adding it there, you need to reload.

Can you share the logs after making the changes. An alternative is install the Python Environments extension. That is a preview extension, a work in progress, but it can help in this scenario: https://marketplace.visualstudio.com/items?itemName=ms-python.vscode-python-envs

@github-actions github-actions bot added the info-needed Issue requires more information from poster label Apr 16, 2025
@curia-damiano
Copy link

I have tried to add the setting at User, Remote and Workspace level, I have closed the remote, reopened, restarted VS Code, rebuilt the container, but nothing...

Then I have installed the extension you suggested. It doesn't find my .venv environment, that is in /workspaces/ProjectName/backend.
If from there I create a new environment (that is created in the root folder of my project), then when I open a new terminal session, the environment is correctly activated.

I would prefer to have the .venv in my backend folder.
Would it be possible to revert the behavior of VS Code to last week?

@karthiknadig
Copy link
Member

@curia-damiano Can you try pinning the Python extension to 2025.2.* to see if that helps this issue? This is really strange that it started failing. Hopefully pinning the extension or the option below should help.

For the Python Envs extension Can you right click on the "backend" folder and select "Add Python Project". That should pick up the venv from backend.

/cc @eleanorjboyd Looks like we may need to revisit #24921

@karthiknadig karthiknadig marked this as a duplicate of #24974 Apr 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
info-needed Issue requires more information from poster triage-needed Needs assignment to the proper sub-team
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants