VSCode terminal shows incorrect python version and path, launching terminal from anaconda works perfectly

后端 未结 5 626
予麋鹿
予麋鹿 2021-02-05 17:03

I have been stuck on this one problem for hours now and believe I have tried everything outside of throwing my computer out of the window.

I have a virtual environment s

相关标签:
5条回答
  • 2021-02-05 17:27

    The officially accepted answer by @Samuel was the correct answer at the time.

    But VS Code has now provided a better way to handle it.

    In short, open up your user settings and add this line of code:

        "terminal.integrated.inheritEnv": false,
    

    This prevents stomping over whatever Python environment manager you are using (eg, venv, conda, etc).

    0 讨论(0)
  • 2021-02-05 17:29

    For Windows users:

    First if you haven't done already, set VS code (the editor, not its terminal) to the desired Python environment, using Ctrl+Shift+P --> Python: Select interpreter.

    Then, Change VS code's default terminal from Powershell to CMD. This is what worked for me at least.

    0 讨论(0)
  • 2021-02-05 17:35

    I have been facing the exact same problem. Finally found a workaround from a forum (https://github.com/Microsoft/vscode-python/issues/4434#issuecomment-466600591)

    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.

    0 讨论(0)
  • 2021-02-05 17:44

    I just ran into the same problem. Try switching out of the powershell terminal to the windows terminal. Then restart. It should restart with the anaconda terminal. If that does not work you could:

    First change the default terminal from within Visual Code to the CMD terminal instead of Powershell. Add the following code to a batch file.

    call "c:\path\to\anaconda3\Scripts\activate"
    

    Then I named the batch file and saved it to my root directory. In my case snake.bat. Now when I launch my CMD terminal I just type c:\snake.bat and the CMD prompt changes into an Anaconda prompt.

    0 讨论(0)
  • 2021-02-05 17:51

    I ran this script. Now python3 is running from virtual env. [Windows 10]

    pip3 install virtualenv
    virtualenv env
    call ".\env\Scripts\activate.bat"
    set requirements="./Requirements.txt"
    pip3 install -r %requirements%
    python
    
    0 讨论(0)
提交回复
热议问题