VSCode Default Shell pointing to wrong python environment

Viewed 408

On my system i have both python 3.8 and python 3.9 installed.

In side my settings.json is the following:

{
    "python.pythonPath": "C:\\Program Files\\Python\\Python38\\python.exe"
}

When i run my python file in VSCode, all is well. However, i want to open a terminal window to create a virtual environment using the above python install. When select 'Terminal: Create new integrate terminal', a command terminal is opened (i have the default set to cmd).

When i then execute 'python --version'. nothing is printed out.

when i execute 'py --version', i see 'Python 3.9.0'.

If do a 'where python', i see 'C:\Users\<user>\AppData\Local\Microsoft\WindowsApps\python.exe'

If i do a 'where py', i see 'C:\Windows\py.exe'

So it doesn't look like i can use the VS Code terminal window to create a virtual environment for the target python version i am currently running in my workspace because it is not the python that is on the path in that terminal window. Does anyone know if this is the expected behavior?

1 Answers

You can choose the environment for which python version should be used, i have python 3.8 and .9 installed too. But i only let vs code use 3.9 . You can do this in the command palette or in settings. Also when importing a file, always check that it it the same python version you want so theres no clashing between versions. This could be one problem of why you have your error as stated.

Related