VS Code does not change python environment
Asked Answered
W

10

6

I am using VS-Code and anaconda environment for python interpreter. I select the exact anaconda base environment by ctrl + shift + ` and it also reflects in the downside panel of vscode. But, when I checked the python version it shows my system's default python environment 3.7.9. If you see the below screenshot than, the anaconda environment is with 3.8.3.

Please give me solution, enter image description hereThank you.

Wandy answered 2/9, 2020 at 9:0 Comment(0)
C
-3

To check & change vs code interpreter:

  • In top left menu bar Click view
  • In the dropdown menu, Click Command Palette
  • Click Python: Select Interpreter
  • Choose & Click on your desired Interpreter

Another way to be sure to use anconda interpreter, open anaconda navigator and launch vs code from there.

original vs code How-To

Conifer answered 2/9, 2020 at 9:22 Comment(0)
P
6

For those who have tried these steps:

  • select different interpreter
  • reboot VScode
  • reinstall VScode Python extension and delete its folders

and have achieved nothing.

Probably you are working in the workspace and not in folder. You may have set interpreter at workspace level, which can't be used in one of the folders of the workspace. Try opening your folder separately from the workspace and select interpreter you want. This worked for me.

Polack answered 28/1, 2023 at 15:11 Comment(1)
can someone clarify what exactly this means? "Try opening your folder separately from the workspace" Am I really unable to use a multi-folder workspace while setting the interpreter?Technics
O
6

For me it worked by changing the final step in the selection process:

The start is as usual:

  • Command Palette
  • > Python: Select Interpreter
  • + Enter interpreter path

but then, not picking the option

  • Find... Browse your file system to find a Python interpreter (which opens a file explorer to select the interpreter)

but instead

  • directly enter the full path in the text field and press Enter.

In theory, both should have the same effect, but for my case they did not. (I had tried reloading the window, restarting vscode, adding the venv to the known venv folders in the workspace settings, even recreating the venv in case something went wrong there, but none of these options worked.)

Orion answered 23/11, 2023 at 15:44 Comment(0)
P
2

Changing the version in VSCode does not change the the instance that your PS instance will use. Try doing where python to see where the V3.7.9 that your PS instance is picking up is. Then remove that version from the environment variables and add the path to the V3.8.3 instead.

Additionally you can do: To forcefully use v3.8.3

  1. Specify python version in command
py -3.8 <command>
  1. OR set PY_PYTHON environment variable to set which version to use. Take a look at this for further help Python docs
Pickwickian answered 2/9, 2020 at 9:12 Comment(1)
what do you mean by PS instance??Canasta
N
2

after changing the environment, you can restart the vs code again. it might be changed now. if not, then try changing now againg by clicking the interpreter name which is displayed on left bottom of the vscode window

Nolie answered 9/2, 2022 at 7:0 Comment(0)
S
0

If nothing worked from the above-suggested solution, you could try this.

Create a virtual environment in anaconda and activate it

conda create -n <environment_name> python=3.8.3

conda activate <environment_name>

Then you can directly open VS Code from same Anaconda terminal by typing

code

In the opened VS Code, you will see python 3.8.3 will be activated. Instead of the default system python 3.7.9

Spoke answered 3/7, 2023 at 10:53 Comment(0)
U
0

In my case helped to uncheck at User settings -> Extensions -> Python:

  • Terminal: Activate Env In Current Terminal
  • Terminal: Activate Environment

but I don`t know why.

Unbreathed answered 12/3, 2024 at 14:58 Comment(0)
K
0

I was able to fix this issue by removing the python.defaultInterpreterPath setting from my settings.json. May be worth checking your user settings if this problem persists.

Another thing I realized is that I have to right-click on the python file and click Run Python file in Terminal, if I just run it with a python command in the powershell window, it's not using the right python executable.

Ketosis answered 26/7, 2024 at 22:0 Comment(0)
T
0

I don't have the conventional way of doing that but when I faced this issue I simply noted the python version that it was showing and then I deleted it as soon as I deleted it the system made another python version as the default python version and then I reinstalled the python version that I deleted and it worked. like I was able to change the python version in VS code.

Tynes answered 20/8, 2024 at 3:37 Comment(0)
R
0

here is how I resolved it with step by step investigation:

  1. first, check all the versions you have installed for example open uninstall program to check all the versions available, uninstall those you don't need

  2. second, find the path to all your existing python versions, default should be "%AppData%\Local\Programs\Python\PythonXXX" for windows users

  3. open "edit system environment", make sure you have the correct python path configured, for example in PATH you have path to python and pip:

"%AppData%\Local\Programs\Python\Python312"

"%AppData%\Local\Programs\Python\Python312\Scripts"

  1. open powershell or cmd, execute:

    python -V

    pip list -v

make sure both are consistent with what you configured in step 3

  1. close all the vscode instances if reload window not work, close all and open up again, then the interpreter selection should work

  2. for best practice, try the virtual env introduced in the link below

refer to:

Python environments in VS Code

python programming

Rote answered 27/9, 2024 at 14:49 Comment(0)
C
-3

To check & change vs code interpreter:

  • In top left menu bar Click view
  • In the dropdown menu, Click Command Palette
  • Click Python: Select Interpreter
  • Choose & Click on your desired Interpreter

Another way to be sure to use anconda interpreter, open anaconda navigator and launch vs code from there.

original vs code How-To

Conifer answered 2/9, 2020 at 9:22 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.