Skip to content

vscode activates conda but points to the default python #4434

Closed

Description

Environment data

  • VS Code version: 1.31.1 (1.31.1)
  • 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:

  1. conda env create -n py36 python=3.6 luigi
  2. conda activate py36
  3. 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)

(base) ZG00021:SERJ philippk$ conda activate py36
(py36) ZG00021:SERJ philippk$ which python
/usr/local/bin/python
(py36) ZG00021:SERJ philippk$ conda --version
conda 4.6.4

Activity

  1. ghost added
    triage-needed
    on Feb 18, 2019
  2. ghost removed
    triage-needed
    on Feb 19, 2019
  3. karrtikr commented on Feb 19, 2019

    @karrtikr

    We don't control how conda handles activation of python. Please file an issue with conda.

  4. ghost removed on Feb 19, 2019
  5. removed their assignment
    on Feb 19, 2019
  6. benlindsay commented on Feb 19, 2019

    @benlindsay

    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.

  7. praenubilus commented on Feb 22, 2019

    @praenubilus

    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.

  8. praenubilus commented on Feb 23, 2019

    @praenubilus

    I've found the similar problem in another old issue #46693

  9. praenubilus commented on Feb 23, 2019

    @praenubilus

    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.

  10. benlindsay commented on Feb 23, 2019

    @benlindsay

    YH (@praenubilus) Thanks for the workaround! Worked like a charm.

  11. praenubilus commented on Feb 27, 2019

    @praenubilus

    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?

  12. DonJayamanne commented on Feb 27, 2019

    @DonJayamanne

    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.

  13. praenubilus commented on Feb 28, 2019

    @praenubilus

    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.

  14. benlindsay commented on Feb 28, 2019

    @benlindsay

    YH (@praenubilus) Are you planning to open a pull request in the VSCode repo to get this fixed?

  15. praenubilus commented on Feb 28, 2019

    @praenubilus

    YH (@praenubilus) Are you planning to open a pull request in the VSCode repo to get this fixed?

    Yes. But I may do it this weekend.

  16. locked as resolved and limited conversation to collaborators on Mar 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions