Skip to content

Conda environment is not activated in Python debug console #12547

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
JackCaster opened this issue Jun 24, 2020 · 2 comments
Closed

Conda environment is not activated in Python debug console #12547

JackCaster opened this issue Jun 24, 2020 · 2 comments
Labels
bug Issue identified by VS Code Team member as probable bug

Comments

@JackCaster
Copy link

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"

@JackCaster JackCaster added triage-needed Needs assignment to the proper sub-team bug Issue identified by VS Code Team member as probable bug labels Jun 24, 2020
@karthiknadig
Copy link
Member

For conda environments we recommend that you start VSCode from an activated prompt. You may still have to select the interpreter, we plan on addressing this (see #10668). We have plans to make the experience better when you create new terminals, see #11039. For terminal that are already open before python extension starts, we recommend that you start VSCode using code . from your project directory from an activated conda prompt.

@brettcannon
Copy link
Member

Closing in favour of the issues Karthik outlined above.

@ghost ghost removed the triage-needed Needs assignment to the proper sub-team label Jun 25, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug
Projects
None yet
Development

No branches or pull requests

3 participants