Repository navigation
Starting VS Code from conda environment fails to activate that environment #23571
Copy link
Copy link
Closed
microsoft/vscode-python-environments
#1243Labels
area-environmentsFeatures relating to handling interpreter environmentsFeatures relating to handling interpreter environmentsbugIssue identified by VS Code Team member as probable bugIssue identified by VS Code Team member as probable bugtriage-neededNeeds assignment to the proper sub-teamNeeds assignment to the proper sub-team
Description
Type: Bug
Behaviour
When starting Visual Studio Code from the terminal with a conda environment activated does say that environment is selected in the status bar (and with the 'run' button, scripts run using that environment's interpreter) but that environment is not activated in the terminal.
Steps to reproduce:
- Open a terminal and activate an environment:
conda activate my_env - Start Visual Studio Code:
code . - See that that
my_envis active, according to the statusbar. - See that pressing the run button does run a Python script using
my_env's Python interpreter. - Open an integrated terminal.
- See that the prompt gives no indication
my_envis activated. - Run:
conda info
and see that only the base environment is activated.
Alternatively, start VS Code from a fresh terminal using:
conda run -n my_env code .with the same results.
Diagnostic data
NOTE: the environment I tested with was actually called cli-board-manager. Sorry about that.
Output for Python in the Output panel (View→Output, change the drop-down the upper-right of the Output panel to Python)
2024-06-07 15:43:46.313 [info] Experiment 'pythonRecommendTensorboardExt' is active
2024-06-07 15:43:46.313 [info] Experiment 'pythonTerminalEnvVarActivation' is active
2024-06-07 15:43:46.313 [info] Experiment 'pythonTestAdapter' is active
2024-06-07 15:43:46.345 [info] Default formatter is set to null for workspace /Users/david/tmp/test-code-env
2024-06-07 15:43:46.352 [info] Test server listening.
2024-06-07 15:43:46.352 [info] VS Code was launched from an activated environment: 'cli-board-manager', selecting it as the interpreter for workspace.
2024-06-07 15:43:46.352 [info] Python interpreter path: /opt/homebrew/Caskroom/miniconda/base/envs/cli-board-manager/bin/python
2024-06-07 15:43:46.363 [info] > pyenv which python
2024-06-07 15:43:46.363 [info] cwd: .
2024-06-07 15:43:46.492 [info] > conda info --json
2024-06-07 15:43:46.492 [info] shell: zsh
2024-06-07 15:43:46.897 [info] > conda run -n cli-board-manager --no-capture-output python ~/.vscode-insiders/extensions/ms-python.python-2024.4.1/python_files/get_output_via_markers.py ~/.vscode-insiders/extensions/ms-python.python-2024.4.1/python_files/printEnvVariables.py
2024-06-07 15:43:46.897 [info] shell: zsh
2024-06-07 15:43:47.313 [info] Starting Pylance language server.
2024-06-07 15:43:47.315 [info] > /opt/homebrew/bin/python3.12 ~/.vscode-insiders/extensions/ms-python.python-2024.4.1/python_files/printEnvVariables.py
2024-06-07 15:43:47.315 [info] shell: zsh
2024-06-07 15:43:47.361 [info] Setting environment variable CONDA_SHLVL in collection to 4 {"applyAtShellIntegration":true,"applyAtProcessCreation":true}
2024-06-07 15:43:47.361 [info] Setting environment variable CONDA_PROMPT_MODIFIER in collection to {"applyAtShellIntegration":true,"applyAtProcessCreation":true}
2024-06-07 15:43:47.362 [info] Setting environment variable _CE_CONDA in collection to {"applyAtShellIntegration":true,"applyAtProcessCreation":true}
2024-06-07 15:43:47.362 [info] Setting environment variable CONDA_PREFIX_3 in collection to /opt/homebrew/Caskroom/miniconda/base {"applyAtShellIntegration":true,"applyAtProcessCreation":true}
2024-06-07 15:43:47.362 [info] Setting environment variable CONDA_PREFIX_2 in collection to /opt/homebrew/Caskroom/miniconda/base/envs/cli-board-manager {"applyAtShellIntegration":true,"applyAtProcessCreation":true}
2024-06-07 15:43:47.362 [info] Setting environment variable _CE_M in collection to {"applyAtShellIntegration":true,"applyAtProcessCreation":true}
2024-06-07 15:43:47.362 [info] Setting environment variable XPC_SERVICE_NAME in collection to 0 {"applyAtShellIntegration":true,"applyAtProcessCreation":true}
2024-06-07 15:43:47.362 [info] Send text to terminal: /opt/homebrew/bin/python3.12 /Users/david/.vscode-insiders/extensions/ms-python.python-2024.4.1/python_files/printEnvVariablesToFile.py /Users/david/.vscode-insiders/extensions/ms-python.python-2024.4.1/python_files/deactivate/zsh/envVars.txt
2024-06-07 15:43:52.355 [info] > conda info --json
Output for Python Debugger in the Output panel (View→Output, change the drop-down the upper-right of the Output panel to Python Debugger)
2024-06-07 15:43:46.494 [info] Name: Python Debugger
2024-06-07 15:43:46.494 [info] Module: debugpy
2024-06-07 15:43:46.494 [error] sendDebugpySuccessActivationTelemetry() failed. [Error: Extension 'ms-python.debugpy' CANNOT use API proposal: debugVisualization.
Its package.json#enabledApiProposals-property declares: portsAttributes, contribIssueReporter but NOT debugVisualization.
The missing proposal MUST be added and you must start in extension development mode or use the following command line switch: --enable-proposed-api ms-python.debugpy
at E (/Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/out/vs/workbench/api/node/extensionHostProcess.js:140:50959)
at Object.registerDebugVisualizationTreeProvider (/Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/out/vs/workbench/api/node/extensionHostProcess.js:162:43818)
at t.registerDebugger (/Users/david/.vscode-insiders/extensions/ms-python.debugpy-2024.6.0-darwin-arm64/dist/extension.js:2:880949)
at e.activate (/Users/david/.vscode-insiders/extensions/ms-python.debugpy-2024.6.0-darwin-arm64/dist/extension.js:2:1128292)
at W.jb (/Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/out/vs/workbench/api/node/extensionHostProcess.js:158:13382)
at W.ib (/Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/out/vs/workbench/api/node/extensionHostProcess.js:158:13092)
at /Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/out/vs/workbench/api/node/extensionHostProcess.js:158:11114
at async c.n (/Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/out/vs/workbench/api/node/extensionHostProcess.js:142:6231)
at async c.m (/Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/out/vs/workbench/api/node/extensionHostProcess.js:142:6194)
at async c.l (/Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/out/vs/workbench/api/node/extensionHostProcess.js:142:5651)]
Extension version: 2024.4.1
VS Code version: Code - Insiders 1.88.0-insider (Universal) (be210b3, 2024-03-15T05:49:14.505Z)
OS version: Darwin arm64 23.5.0
Modes:
- Python version (& distribution if applicable, e.g. Anaconda): 3.12.3
- Type of virtual environment used (e.g. conda, venv, virtualenv, etc.): Conda
- Value of the
python.languageServersetting: Default
User Settings
languageServer: "Pylance"
Installed Extensions
| Extension Name | Extension Id | Version |
|---|---|---|
| JavaScript Debugger | ms-vscode.js-debug | 1.87.0 |
| JavaScript Debugger Companion Extension | ms-vscode.js-debug-companion | 1.1.2 |
| Pylance | ms-python.vscode-pylance | 2024.6.1 |
| Python | ms-python.python | 2024.4.1 |
| Python Debugger | ms-python.debugpy | 2024.6.0 |
| Table Visualizer for JavaScript Profiles | ms-vscode.vscode-js-profile-table | 1.0.8 |
System Info
| Item | Value |
|---|---|
| CPUs | Apple M2 Pro (12 x 24) |
| 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 |
| Load (avg) | 2, 2, 3 |
| Memory (System) | 16.00GB (0.12GB free) |
| Process Argv | . --crash-reporter-id 1571364c-c8c2-454c-9aea-30d78628cd73 |
| Screen Reader | no |
| VM | 0% |
A/B Experiments
vsliv368:30146709
vspor879:30202332
vspor708:30202333
vspor363:30204092
vscod805:30301674
vsaa593cf:30376535
py29gd2263:31024238
c4g48928:30535728
a9j8j154:30646983
962ge761:30841072
pythongtdpath:30726887
welcomedialog:30812478
pythonidxpt:30768918
pythonnoceb:30776497
asynctok:30898717
dsvsc013:30777762
dsvsc014:30777825
dsvsc015:30821418
pythontestfixt:30866404
pythonregdiag2:30926734
pythonmypyd1:30859725
pythoncet0:30859736
2e7ec940:31000449
pythontbext0:30879054
accentitlementst:30870582
dsvsc016:30879898
dsvsc017:30880771
dsvsc018:30880772
cppperfnew:30980852
pythonait:30973460
jchc7451:31067543
showvideot:31016890
chatpanelt:31014475
0ee40948:31013168
a69g1124:31018687
dvdeprecation:31040973
pythonprt:31036556
dwnewjupyter:31046869
impr_priority:31057980
26j00206:31048877
nativerepl2:31063928
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
area-environmentsFeatures relating to handling interpreter environmentsFeatures relating to handling interpreter environmentsbugIssue identified by VS Code Team member as probable bugIssue identified by VS Code Team member as probable bugtriage-neededNeeds assignment to the proper sub-teamNeeds assignment to the proper sub-team
Activity
karthiknadig commentedon Jun 7, 2024
code .orcode project.code-workspaceto launch VS Code.This will give you an activated environment, and the extension will not have to try and activate every time a terminal is created.
Also, look for the inherit env setting and see if toggling it helps.
davidfokkema commentedon Jun 10, 2024
I disabled both settings and tried both variations of "inherit env". Whenever I run VS Code from an activated environment, only the base environment is activated in the integrated terminals. So, unfortunately, this did not work.
davidfokkema commentedon Aug 31, 2024
BTW, this is certainly related to #22879 since before that, it worked just fine.
davidfokkema commentedon Oct 9, 2024
I copy/pasted the output of the Python extension in VS Code in the case of running
codefrom the base environment, and runningcodefrom a conda environment (testabc). I looked at the diff. Three observations when running from thetestabcenvironment (which results in a broken terminal):[info] VS Code was launched from an activated environment: 'testabc', selecting it as the interpreter for workspace., which is nice because you don't have to manually select the correct interpeter. Love this![info] Prepending environment variable PATH in collection to /Users/david/.cargo/bin:/Users/david/perl5/bin:/opt/homebrew/Caskroom/miniconda/base/envs/testabc/bin:etc. etc. which is actually the only thing missing to correctly activate the environment.[info] Setting environment variable CONDA_DEFAULT_ENV in collection to testabc {"applyAtShellIntegration":true,"applyAtProcessCreation":true}, which sets the environment name in the prompt and shows that it is activated.Ad 2.: Since the extension correctly figures out the environment, it should be no problem to add to the path. It looks like the extension when running 'clean' takes the PATH from
conda info --json, replaces the string containing the location of the base environment with the location of thetestabcenvironment (determined when manually selecting the interpreter) and prepends that to the PATH of the newly-created terminal. Nice. When starting from the environment, however, the PATH fromconda info --jsonis already correct. However: VS Code creates a new env from a login shell which does not contain any conda initialisation so the correct PATH is nuked? The setting 'inherit env' didn't seem to do anything, also on macOS.Another observation: VS Code claims:
[debug] VS Code was not launched from the command linebut I literally typedcode .in a terminal.davidfokkema commentedon Oct 9, 2024
So, I guess the solution would be to execute steps 2 and 3 (see above) no matter when you're running from an activated environment or not. If I manually apply those two steps after creating a terminal, that terminal is fixed.
Work around a VS code bug when activating environments
eleanorjboyd commentedon Dec 8, 2025
Hi there! 👋
Thanks again for reporting this issue. Based on what you described, this appears to touch the same parts of our environment/activation logic that we’ve recently replaced in our new Python Environments extension. A lot of the behavior in this area now follows a completely different activation and environment-resolution path, so this may already be fixed.
We’d really appreciate it if you could try the new extension and let us know—this helps us confirm that the new implementation addresses older issues like yours.
👉 Enable the new extension with
"python.useEnvironmentsExtension": true(then you should see aPythonicon in the sidebar.📫 More details on enablement here
📝 Useful background documentation on activation here
If you do run into issues, please include as much info and reproduction steps or the "Report issue..." command inside VS Code!
Thanks again for reporting this originally, and for helping us validate the new environment direction for Python in VS Code 🙌
KeilFelix commentedon Jan 7, 2026
I came across this issue, because I observed the same problem, that only the base environment is activated in my vs code terminals.
So I added
"python.useEnvironmentsExtension": trueto my settings json and selected my environment. I also set my environment via Python (Sidebar) -> Environment Managers -> MyEnv -> "Set As Project Environment".Afterwards I think I still needed to manually activate once and/or reopen VsCode. Then all new terminals were in my environment again. 👍
But you always see now that the terminal is not directly with MyEnv activated. Instead id is opened in base environment always and then
(C:\Users\my\miniconda3\shell\condabin\conda-hook.ps1) ; (conda activate MyEnv) is immediately executed.
This is how opening a terminal now looks like for me:
Btw. I noticed that the "Create Python Terminal" action under Environment Managers ignores "terminal.integrated.cwd" in settings.json. I think it should not.
Still unsure if all my tasks that I configured in tasks.json are running in the correct environment.
KeilFelix commentedon Jan 7, 2026
Update - Further discovered issues:
Tasks from tasks.json execute in my MyEnv which is good.
github-actions commentedon Feb 11, 2026
Hey Karthik Nadig (@karthiknadig), this issue might need further attention.
David Fokkema (@davidfokkema), you can help us out by closing this issue if the problem no longer exists, or adding more information.
davidfokkema commentedon Feb 13, 2026
I've tested this on Windows. The behaviour has changed, but I'm not sure if it is for the better. I did:
conda activate my_envcode .Select Python Interpreterin the bottom-right of the window).It used to be that VS Code would activate the environment that was active in the shell it ran from.
eleanorjboyd commentedon Feb 17, 2026
David Fokkema (@davidfokkema) the intent is it uses the environment which is active. Karthik Nadig (@karthiknadig) did some work here specifically to respect the environment set in the terminal before starting see microsoft/vscode-python-environments@cc45070. Can you check before launching vscode if VIRTUAL_ENV is set and make sure that value is the one you expect. Additionally, do you have anything in your settings.json for this workspace/ your user related to
python-envs.pythonProjectsordefaultInterpreterPath?karthiknadig commentedon Feb 17, 2026
Actually we probably need to check CONDA specific variable equivalent to VIRTUAL_ENV in this case. Similar to how this is handled for venv.
davidfokkema commentedon Feb 18, 2026
Eleanor Boyd (@eleanorjboyd) Karthik Nadig (@karthiknadig) This does seem to work for 'normal' virtual environments, indeed, when you don't have workspace-specific settings overriding the environment selection.
add support for `CONDA_PREFIX` set already in vscode environment (mic…