-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
VSCode is activating Conda environment after code launcher run, instead of before. #13262
Comments
@RichardCoppin This is a known issue. #5559 (which is covered by a broader set of terminal issues #4568). The recommended way, until we address, this is:
|
I have the exact same issue. +1 |
A very irritating issue |
It would be nice to add the option to put conda activation script in launch.json. This would enable using different environments for debugging. Currently you can put activation script in tasks.json, but it doesn't quite work since tasks don't use the same terminal |
Environment data
Version: 1.47.3 (system setup)
Commit: 91899dcef7b8110878ea59626991a18c8a6a1b3e
Date: 2020-07-23T13:12:49.994Z
Electron: 7.3.2
Chrome: 78.0.3904.130
Node.js: 12.8.1
V8: 7.8.279.23-electron.0
OS: Windows_NT x64 10.0.19041
Python Extension: v2020.7.96456
Python version (& distribution if applicable, e.g. Anaconda): Python 3.8.3 (Anaconda)
Type of virtual environment used (N/A | venv | virtualenv | conda | ...): (base)
Relevant/affected Python packages and their versions: NumPy version 1.18.5
PATH:
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.0\bin;C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.0\libnvvp;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files\dotnet\;C:\Program Files\Git\cmd;C:\Program Files\NVIDIA Corporation\Nsight Compute 2020.1.1\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR;C:\Program Files\Microsoft VS Code\bin;%HOME%\AppData\Local\Microsoft\WindowsApps;
settings.json
launch.json
~/.bashrc
Example Code: numpytest.py
Expected behaviour
I would expect the conda environment to be activated before the code is debugged (or executed). however this seems to be happening in reverse.
Activates Conda Environment
$ c:/ProgramData/Anaconda3/Scripts/activate
$ conda activate c:/ProgramData/Anaconda3
Executes launcher:
env c:/ProgramData/Anaconda3/python.exe c:\\Users\\...\\.vscode\\extensions\\ms-python.python-2020.7.96456\\pythonFiles\\lib\\python\\debugpy\\launcher 51465 -- c:\\Users\\...\\Documents\\numpytest.py
Actual behaviour
Executes launcher:
env c:/ProgramData/Anaconda3/python.exe c:\\Users\\...\\.vscode\\extensions\\ms-python.python-2020.7.96456\\pythonFiles\\lib\\python\\debugpy\\launcher 51465 -- c:\\Users\\...\\Documents\\numpytest.py
Numpy throws ImportError
Activates Conda Environment
$ c:/ProgramData/Anaconda3/Scripts/activate
$ conda activate c:/ProgramData/Anaconda3
Manually executing the script from the command line at this point succeeds.
$ python c:\\Users\\...\\Documents\\numpytest.py
Hello World
Steps to reproduce:
I'm observing this behaviour both using Git-Bash as well as CMD as default shell in VSCode, but I do not see this same import error in Spyder, or in a terminal (anaconda cmd or Git-Bash). I also only see this issue when I try to import numpy modules (or any derivatives eg. pandas). The code also runs (without the error) in an integrated terminal within VScode.
All of the settings are straight forward the only one I've amended was the
"terminal.integrated.shellArgs.windows"
setting it to["-l"]
so that the bash terminal actually imports the ~/.bashrc, so that python can run in the shell.I can get this to work by activating conda within a terminal, then manually executing vscode from within the same terminal, but this is less than ideal.
TL;DR:
Everything is pointing to the fact that if the conda environment was just activated before the script is called everything would just work.
Logs
This is the screenshot of the error in the UI.
Output for
Python
in theOutput
panel (View
→Output
, change the drop-down the upper-right of theOutput
panel toPython
)The text was updated successfully, but these errors were encountered: