Skip to content

Conda environment is not activated in Python debug console #12547

@JackCaster

Description

@JackCaster

Environment data

  • VS Code version: 1.43.2
  • Extension version (available under the Extensions sidebar): 2020.5.86806 (10 June 2020)
  • OS and version: Win 10 Pro
  • Python version (& distribution if applicable, e.g. Anaconda): conda 4.8.3
  • Type of virtual environment used (N/A | venv | virtualenv | conda | ...): conda
  • Relevant/affected Python packages and their versions: XXX
  • Relevant/affected Python-related VS Code extensions and their versions: XXX
  • Value of the python.languageServer setting: microsoft

Expected behaviour

I set the option "python.terminal.activateEnvInCurrentTerminal": true. The current conda environment is correctly activated when the script is run normally without debugger. I would expect this to work also when the script is run with the debugger

Actual behaviour

However, when the script is run with the debugger the conda environment is not correctly activate and it require to restart the debugger. At the first run, the console will run C:/miniconda/Scripts/activate to activate conda to the base environment. Conda will not activate the project environment. Restarting the debugger will make vscode now run conda activate name_of_the_project_env before stepping into the code.
`

C:\Dev\test_conda>C:/miniconda/Scripts/activate #<-- Activate conda base

(base) C:\Dev\test_conda> cmd /C "C:\miniconda\envs\test\python.exe c:\Users\jack\.vscode\extensions\ms-python.python-2020.5.86806\pythonFiles\lib\python\debugpy\wheels\debugpy\launcher 51750 -- c:\Dev\test_conda\test.py "
SCRIPT RUN #<-- Run the script before the env is activated

(base) C:\Dev\test_conda>conda activate test # <-- Now the env is activated

(test) C:\Dev\test_conda> 

Logs

Output for Python in the Output panel (ViewOutput, change the drop-down the upper-right of the Output panel to Python)

User belongs to experiment group 'ShowPlayIcon - start'
User belongs to experiment group 'DebugAdapterFactory - experiment'
User belongs to experiment group 'PtvsdWheels37 - experiment'
User belongs to experiment group 'UseTerminalToGetActivatedEnvVars - control'
User belongs to experiment group 'LocalZMQKernel - control'
User belongs to experiment group 'CollectLSRequestTiming - control'
User belongs to experiment group 'CollectNodeLSRequestTiming - experiment'
User belongs to experiment group 'EnableIPyWidgets - experiment'
User belongs to experiment group 'DeprecatePythonPath - experiment'
User belongs to experiment group 'RunByLine - control'
User belongs to experiment group 'CustomEditorSupport - control'
> pyenv root
> python3.7 c:\Users\jack\.vscode\extensions\ms-python.python-2020.5.86806\pythonFiles\pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> python3.6 c:\Users\jack\.vscode\extensions\ms-python.python-2020.5.86806\pythonFiles\pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> python3 c:\Users\jack\.vscode\extensions\ms-python.python-2020.5.86806\pythonFiles\pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> python2 c:\Users\jack\.vscode\extensions\ms-python.python-2020.5.86806\pythonFiles\pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> python c:\Users\jack\.vscode\extensions\ms-python.python-2020.5.86806\pythonFiles\pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> py -3.7 c:\Users\jack\.vscode\extensions\ms-python.python-2020.5.86806\pythonFiles\pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> py -3.6 c:\Users\jack\.vscode\extensions\ms-python.python-2020.5.86806\pythonFiles\pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> py -3 c:\Users\jack\.vscode\extensions\ms-python.python-2020.5.86806\pythonFiles\pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> py -2 c:\Users\jack\.vscode\extensions\ms-python.python-2020.5.86806\pythonFiles\pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> python c:\Users\jack\.vscode\extensions\ms-python.python-2020.5.86806\pythonFiles\pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> C:\miniconda\condabin\conda.bat info --json
> python c:\Users\jack\.vscode\extensions\ms-python.python-2020.5.86806\pythonFiles\pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> python c:\Users\jack\.vscode\extensions\ms-python.python-2020.5.86806\pythonFiles\pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> C:\miniconda\condabin\conda.bat env list
> python c:\Users\jack\.vscode\extensions\ms-python.python-2020.5.86806\pythonFiles\pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> python c:\Users\jack\.vscode\extensions\ms-python.python-2020.5.86806\pythonFiles\pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
Starting Microsoft Python language server.
Python interpreter path: C:\miniconda\envs\test\python.exe
> C:\Python38\python.exe c:\Users\jack\.vscode\extensions\ms-python.python-2020.5.86806\pythonFiles\pyvsc-run-isolated.py -c "import jupyter"
> C:\Python38\python.exe c:\Users\jack\.vscode\extensions\ms-python.python-2020.5.86806\pythonFiles\pyvsc-run-isolated.py -c "import jupyter"
> C:\Python38\python.exe c:\Users\jack\.vscode\extensions\ms-python.python-2020.5.86806\pythonFiles\pyvsc-run-isolated.py -c "import notebook"
> C:\Python38\python.exe c:\Users\jack\.vscode\extensions\ms-python.python-2020.5.86806\pythonFiles\pyvsc-run-isolated.py -c "import notebook"
> C:\miniconda\condabin\conda.bat info --json
> C:\miniconda\condabin\conda.bat env list


Output from Console under the Developer Tools panel (toggle Developer Tools on under Help; turn on source maps to make any tracebacks be useful by running Enable source map support for extension debugging)

I do not know what you mean with "running Enable source map support for extension debugging"

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIssue identified by VS Code Team member as probable bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions