Reputation: 727
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, Thank you.
Upvotes: 6
Views: 25184
Reputation: 2007
here is how I resolved it with step by step investigation:
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
second, find the path to all your existing python versions, default should be "%AppData%\Local\Programs\Python\PythonXXX" for windows users
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"
open powershell or cmd, execute:
python -V
pip list -v
make sure both are consistent with what you configured in step 3
close all the vscode instances if reload window not work, close all and open up again, then the interpreter selection should work
for best practice, try the virtual env introduced in the link below
refer to:
Python environments in VS Code
Upvotes: 0
Reputation: 1
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.
Upvotes: 0
Reputation: 917
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.
Upvotes: 0
Reputation: 1
In my case helped to uncheck at User settings -> Extensions -> Python:
but I don`t know why.
Upvotes: 0
Reputation: 122
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
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.)
Upvotes: 8
Reputation: 51
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
Upvotes: 0
Reputation: 81
For those who have tried these steps:
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.
Upvotes: 6
Reputation: 3491
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
Upvotes: 2
Reputation: 98
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
py -3.8 <command>
Upvotes: 2
Reputation:
To check & change vs code interpreter:
Another way to be sure to use anconda interpreter, open anaconda navigator and launch vs code from there.
Upvotes: -3