Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you get Visual Studio Code to use different Python interpreter?

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

like image 479
NL3294 Avatar asked Oct 20 '19 06:10

NL3294


People also ask

How do I select a Python compiler in Visual Studio code?

From the Command Palette (Ctrl+Shift+P), select the Python: Start REPL command to open a REPL terminal for the currently selected Python interpreter. In the REPL, you can then enter and run lines of code one at a time.

Why Python interpreter is not showing in VS Code?

Install Python and the Python extension# Once you have a version of Python installed, activate it using the Python: Select Interpreter command. If VS Code doesn't automatically locate the interpreter you're looking for, refer to Environments - Manually specify an interpreter.


2 Answers

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.

like image 199
Hamidreza Avatar answered Sep 22 '22 19:09

Hamidreza


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

like image 32
ThatAnnoyingDude Avatar answered Sep 25 '22 19:09

ThatAnnoyingDude