9

I'm new to VS Code/Python, and I'm trying to get VSCode to run a specific version of Python (seems I have multiple versions installed).

I tried the following code:

import sys
print(sys.version)

When I run the file, some reason, it shows:

  3.5.2 |Anaconda 4.2.0 (32-bit)| (default, Jul  5 2016, 11:45:57) [MSC v.1900 32 bit (Intel)]

I've tried the following: At the very bottom of VSCode, I clicked on the Python version, then clicked on "Python 3.7.3 64-bit", but when I reran the code, it still shows "3.5.2 |Anaconda..."

I also tried checking the settings, and it's showing:

  Python: Python Path
    C:\Users\[MY_USE_NAME]\AppData\Local\Programs\Python\Python37-32\python.exe

I also tried just typing "python" in the command like, and it still says "Python 3.5.2".

Any idea what I'm doing wrong? I'm very new to VS Code, so hopefully it's something simple.

screenshot

NL3294
  • 984
  • 1
  • 10
  • 27

5 Answers5

5

For choosing interpreter, press ctrl + p and then type >Python: Select Interpreter (don't forget the > character! if it doesn't show up, make sure you have installed python extension on your vs code) and select one of the options. It will show you available interpreters (virtual environments + the global environment) to choose.

If you want to change version of python you are using, you must first create a virtual environment with desired version of python and then choose it as your interpreter. (I recommend to create it in .venv directory in the root directory of your project)

This answer will help you with that.

Hamidreza
  • 1,465
  • 12
  • 31
  • solved my problem! ONLY when I manually browsed and selected the desired interpreter NOT when I provided the path for the interpreter in the input box by pasting the folder path. Strange!! – Sudhansu Choudhary Aug 01 '21 at 16:55
3

Open command pallete with F1 (on Windows) and type Python: Select Interpreter.

  • 1
    I tried that. I just set it to Python Path: E:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\python. But when I test it, it still shows 3.5.2 |Anaconda. I set the path under both the User tab and the Workspace tab. – NL3294 Oct 20 '19 at 07:15
  • You can either play around with venv or edit your windows path env variable in `Edit the system environment variables` of the start menu. Or you also can do `Python: Run Selection/Line in Python terminal` on some non empty line of the source code to open the python shell, but it is hacky. The problem is that when you open the intergrated terminal it still uses PATH variable to find python executable. – ThatAnnoyingDude Oct 20 '19 at 07:52
  • Thanks. Updating the Path worked. But is my setup not working correctly? I would have thought that selecting the environment in VSCode would make that the default. I thought that selector on the bottom left corner of VS code was there so that I could switch back and forth easier. Or am I not understanding correctly? – NL3294 Oct 20 '19 at 17:32
  • 1
    It is for changing the path for python that Python extension will use to run/debug your scripts and provide intellisense. It doesn't affect the intergrated terminal though. – ThatAnnoyingDude Oct 20 '19 at 18:55
  • 1
    @ThatAnnoyingDude, your last comment is not true anymore. There is a Visual Studio Code command to make the Terminal to use the interpreter now. https://code.visualstudio.com/docs/python/environments#_environments-and-terminal-windows – JustBeingHelpful Jan 25 '21 at 23:14
1

In the bottom left of the footer bar, you should see some text that says something like Python 3.x Python 3.7.4

Click on that text. In the top middle of the window, you should then see a dialog where you can select your version of python

Select python version

AutoPlay5
  • 35
  • 8
  • I did that. See my original question: "I've tried the following: At the very bottom of VSCode, I clicked on the Python version, then clicked on "Python 3.7.3 64-bit", but when I reran the code, it still shows "3.5.2 |Anaconda..."" I also tried restarting VS Code and I still get the same problem. I added a screenshot. – NL3294 Oct 20 '19 at 07:17
  • i didn't see this in my footer. help! – greendino Feb 22 '22 at 12:33
0

I had the same problem, I had select the python interpreter but when I run my terminal, another version of python appeared.

I reinstall the version of python that I want to run but I selected all the options in the installer. When it finished, I open visual Studio Code and it works! Maybe, this was because I just installed the python for me and not for "all users".

Image

0

just try modify option from the installer and allow all users and close and open the vscode again. It worked for me

legend
  • 1
  • 1
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jun 19 '22 at 04:55