Sandun
Sandun

Reputation: 415

Python3 seems not to be recognized in VSCode

I had Python version 2.7.17 already installed on my machine. Recently I started coding in Python and I installed VS Code to make things easier. However once I opened VSCode and ran a simple Python Hello World program, VSCode terminal gave a warning saying that

Python 2 support has ended at January 1, 2020

which means the support has already ended and suggested to install the latest Python version. So I heeded the warning and installed Python 3.8.5 on my Windows machine. The installation was completed without any issue. Afterward, when I tried the command python --version on VSCode terminal, it correctly gave the output python 2.7.17. However, when I tried the command python3 --version to check if it was correctly installed, the terminal gave no output.

Since I am a beginner and the support for Python 2 has already ended, I would like to work with Python3 from now on. However, I don't mind Python 2 staying in the machine.

Is this something should I worry about? Or should I uninstall Python 2 completely (When I checked Control Panel both versions are list under currently installed programs)?

Upvotes: 2

Views: 5750

Answers (2)

Molly Wang-MSFT
Molly Wang-MSFT

Reputation: 9471

According to your description, you can change pythonpath in vscode and still keep python2.

I assume you are using windows system and if not, please let me know. The following is the solution:

  1. open cmd and type: where python. There should be two path, copy it which is about python3.8.5;
  2. press Ctrl+, to open setting.json and add an entry for python.pythonPath manually inside your User Settings:

enter image description here

Now you can press Ctrl+Shift+P and find the option select interpreter. Click it you'll find a interpreter list. After selecting new interpreter, it is necessary to press Ctrl+Shift+` to open a new terminal for further development.

About more detailed information about pythonpath and interpreter you can refer to using python environments in vscode.

Upvotes: 3

rbatt
rbatt

Reputation: 4807

The version of Python used depends on your environment, and PATH variable.

I think you need to select the correct Python interpreter. At the bottom of your screen, there should be something that says the Python version number. If you click it, you can get a menu to select the interpreter.

Alternatively, you can hit control-shift-p, type "python interpreter", then click "select python interpreter" option.

Finally, you can alter the default Python interpreter used by changing the User settings in VS Code. Hit control-shift-p, type "open settings", and select Open Settings (JSON). Add a key to the JSON file called "python.pythonPath", so that you have a line that looks something like this:

"python.pythonPath": "full/path/to/the/python/executable/you/want/python.exe",

You might be able to get a hint as to the path to use or available isntallations of python if you type where python or which python (depending on terminal/ OS in use).

Then you can save those settings. Restart VS Code. Hopefully now the correct interpreter is selected by default.

Upvotes: 0

Related Questions