You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
vscode activates conda but points to the default python #4434
Extension version (available under the Extensions sidebar): 2019.1.0
OS and version: MacOS 10.14.3 (18D42)
Python version (& distribution if applicable, e.g. Anaconda): Python 3.6, conda 4.6.4
Type of virtual environment used (N/A | venv | virtualenv | conda | ...): conda
Expected behavior
when conda activate env, anaconda's python is used. this works in the shell terminal
Actual behavior
when conda activate env, terminal states that env is activated - prints (env) at the beginning of the line. Same with the interpreter - VScode sees it and I am able to select it.
However, which python points to the default python on MacOS, and therefore none python 3.6-dependent packages work. Same with the interpreter - VScode fails to find packages which are installed in the env
Steps to reproduce:
conda env create -n py36 python=3.6 luigi
conda activate py36
which python // in vscode terminal
Logs
Output for Python in the Output panel (View→Output, change the drop-down the upper-right of the Output panel to Python)
___________________ ERROR collecting tests/test_reporter.py ____________________
ImportError while importing test module '/Users/philippk/Dropbox/se_projects/4_Automation/SERJ/tests/test_reporter.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
test_reporter.py:5: in <module>
from SE.areas import get_all_areas
E ModuleNotFoundError: No module named 'SE'
!!!!!!!!!!!!!!!!!!! Interrupted: 3 errors during collection !!!!!!!!!!!!!!!!!!!!
PROBLEMS similarly complains about lack of packages installed and type hints.
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)
If this problem is the same as my problem in #4436, then I don't think it's a conda issue. Notice that when I open iterm2 and manually run the exact same commands that VSCode appears to be running (source /Users/benlindsay/miniconda/bin/activate and conda activate ads) , everything works as expected. My PATH only gets messed up with the automatic conda activation.
On that note, Philipp Kats (@Casyfill), could you print the results of echo $PATH after the failed conda activation? I'm curious to see if you also have duplicate paths in front of path to your environment's bin directory.
Having the same problem with recent update. And I think the reason maybe how vscode handle shell initialization in Mac. So if you open a terminal outside of VSCode, the $PATH will be set by following initial script from anaconda in your bash_profile or zshrc(if you are using zsh). export PATH="/Users/xxx/anaconda3/bin:$PATH"
After that, if you do a echo $PATH, you will see value similar as following: /Users/xxx/anaconda3/bin:/Users/xxx/anaconda3/condabin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
However, when you fire up vscode, for some reason, the anaconda PATH has been APPENDED to system default PATH, not PREPEND. Check with echo $PATH in vscode terminal, you will see path similar as following: /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/xxx/anaconda3/bin:/Users/xxx/anaconda3/condabin
It appeared in recent vscode version, but I'm not sure if it starts from 1.31.1 on Mac.
The terminal command python will match the first executable python it found in the PATH, in vscode, it will find the default system one based on PATH value.
Find some dark magic for workaround. In case someone with the same problem need a solution. As long as you ADD some stuff to configuration, terminal.integrated.env.osx, the content will be appended to PATH after shell initialization(source bash_profile or zshrc). In my Mojave, I simply add following empty entry to my user configuration:
"terminal.integrated.env.osx": {
"PATH": ""
}
Then the $PATH will be the same as the external terminal.
Too busy to dive into the source code to check the root cause, maybe do it later when I have more time.
Reacted by Ben Lindsay, Yue Gao and Florian Gaudin-Delrieu
Don Jayamanne (@DonJayamanne) I'm not sure whether you considered this as an issue. Actually I've located the source code and I can fix it, if I will submit a pull request, which sub-project/issue will you recommend me to submit? vscode?
The fact that you had to modify the settings to get this work and it has nothing to do with the extension means, it's not the extension that needs any PRs to resolve this.
The fact that you had to modify the settings to get this work and it has nothing to do with the extension means, it's not the extension that needs any PRs to resolve this.
Yes, I agree. There is nothing to do with the python extension.
Activity
karrtikr commentedon Feb 19, 2019
We don't control how conda handles activation of python. Please file an issue with conda.
benlindsay commentedon Feb 19, 2019
If this problem is the same as my problem in #4436, then I don't think it's a conda issue. Notice that when I open iterm2 and manually run the exact same commands that VSCode appears to be running (
source /Users/benlindsay/miniconda/bin/activateandconda activate ads) , everything works as expected. MyPATHonly gets messed up with the automatic conda activation.On that note, Philipp Kats (@Casyfill), could you print the results of
echo $PATHafter the failed conda activation? I'm curious to see if you also have duplicate paths in front of path to your environment's bin directory.praenubilus commentedon Feb 22, 2019
Having the same problem with recent update. And I think the reason maybe how vscode handle shell initialization in Mac. So if you open a terminal outside of VSCode, the $PATH will be set by following initial script from anaconda in your bash_profile or zshrc(if you are using zsh).
export PATH="/Users/xxx/anaconda3/bin:$PATH"After that, if you do a
echo $PATH, you will see value similar as following:/Users/xxx/anaconda3/bin:/Users/xxx/anaconda3/condabin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbinHowever, when you fire up vscode, for some reason, the anaconda PATH has been APPENDED to system default PATH, not PREPEND. Check with
echo $PATHin vscode terminal, you will see path similar as following:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/xxx/anaconda3/bin:/Users/xxx/anaconda3/condabinIt appeared in recent vscode version, but I'm not sure if it starts from 1.31.1 on Mac.
The terminal command python will match the first executable python it found in the PATH, in vscode, it will find the default system one based on PATH value.
praenubilus commentedon Feb 23, 2019
I've found the similar problem in another old issue #46693
praenubilus commentedon Feb 23, 2019
Find some dark magic for workaround. In case someone with the same problem need a solution. As long as you ADD some stuff to configuration,
terminal.integrated.env.osx, the content will be appended to PATH after shell initialization(source bash_profile or zshrc). In my Mojave, I simply add following empty entry to my user configuration:Then the $PATH will be the same as the external terminal.
Too busy to dive into the source code to check the root cause, maybe do it later when I have more time.
benlindsay commentedon Feb 23, 2019
YH (@praenubilus) Thanks for the workaround! Worked like a charm.
praenubilus commentedon Feb 27, 2019
Don Jayamanne (@DonJayamanne) I'm not sure whether you considered this as an issue. Actually I've located the source code and I can fix it, if I will submit a pull request, which sub-project/issue will you recommend me to submit? vscode?
DonJayamanne commentedon Feb 27, 2019
The fact that you had to modify the settings to get this work and it has nothing to do with the extension means, it's not the extension that needs any PRs to resolve this.
praenubilus commentedon Feb 28, 2019
Yes, I agree. There is nothing to do with the python extension.
benlindsay commentedon Feb 28, 2019
YH (@praenubilus) Are you planning to open a pull request in the VSCode repo to get this fixed?
praenubilus commentedon Feb 28, 2019
Yes. But I may do it this weekend.