Skip to content

Starting VS Code from conda environment fails to activate that environment #23571

@davidfokkema

Description

@davidfokkema

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:

  1. Open a terminal and activate an environment:
    conda activate my_env
  2. Start Visual Studio Code:
    code .
  3. See that that my_env is active, according to the statusbar.
  4. See that pressing the run button does run a Python script using my_env's Python interpreter.
  5. Open an integrated terminal.
  6. See that the prompt gives no indication my_env is activated.
  7. 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 (ViewOutput, 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 (ViewOutput, 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.languageServer setting: 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

Metadata

Metadata

Assignees

Labels

area-environmentsFeatures relating to handling interpreter environmentsbugIssue identified by VS Code Team member as probable buginfo-neededIssue requires more information from postertriage-neededNeeds assignment to the proper sub-team

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions