[Django]-VSCode terminal shows incorrect python version and path, launching terminal from anaconda works perfectly

42πŸ‘

βœ…

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.

35πŸ‘

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).

3πŸ‘

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.

2πŸ‘

Windows Solution:

If anyone in the future ends up scratching their heads over this particular problem, I’ve found another culprit, which blocked me for this problem on Windows:

Showcase of setting
Terminal>Integrated>Env: Enable Persistent Sessions

I suspect what happens is that after you update system paths, VScode caches the old path in the terminal and persists it. In this case it persists the old python path rather than the new conda one.

Toggling this option off and restarting VSCode clears that cache, and the new path is loaded in. You can also toggle the option back on after you’re done.

1πŸ‘

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.

-1πŸ‘

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

Leave a comment