简体   繁体   中英

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.

截屏

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.

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

In the bottom left of the footer bar, you should see some text that says something like Python 3.xPython 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

选择python版本

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM