0

I just installed VS Code, Python (version 3.7.5 released on Oct.15, 2019) on MacOS. So I run python --version on my VS Code Terminal, the result showed Python 2.7.11.

Shouldn't it be 3.7.5?

General Grievance
  • 4,555
  • 31
  • 31
  • 45

4 Answers4

0

You need to select the Python version you want to use for VS Code. See here

I would also recommend setting up virtual environments if you plan to do a significant amount of Python work.

Paul D.
  • 591
  • 7
  • 17
  • Paul, what is a virtual environment what is benefits of set up? – jinsapearl Mar 14 '20 at 15:41
  • @jinsapearl The comments are not an appropriate place for discussions like this. You should do some research, then create a new question if necessary. – dspencer Mar 14 '20 at 15:43
  • A virtual environment is an isolated Python installation including associated packages. It allows you to freeze the python version and libraries when you develop. If you develop multiple Python applications, all using the same version and packages you will run into conflicts. Google it for a more in depth explanation. – Paul D. Mar 14 '20 at 15:44
  • @paul I am a total beginner even just using python and vs code made me feel so lost ... is it normal? – jinsapearl Mar 14 '20 at 15:45
0

As per the comment discussion, you have two versions of python installed, 2.7.11 and 3.7.5.

To use 3.7.5, you need to execute it as python3. python3 --version gives the expected output.

dspencer
  • 4,297
  • 4
  • 22
  • 43
0

In case you want to run python --version instead of python3 --version.You can use pyenv to set a global version of python. Once it’s done, you can just run python --version, and the result will be the version of your global python.

Pyenv only deals with the python installed by pyenv itself, so if you want to use it, you may reinstall the specific version you want via pyenv.

Pyenv is also a tool to manage your virtual environment, and I guess you can kill two birds with one stone. There are two friendly articles explaining the virtual environment and pyenv respectively.

predawn
  • 33
  • 4
0

Installing Python version 3+ does not overwrite Python 2. So you may have both versions configured on your system. To check the version of each, use:

python2 --version
python3 --version

To identify if one is defaulting higher than the other, you can use the following to trace the path of both versions.

which python2
which python3

Depending on how close the paths are to your root, one may be defaulting to the other.

JRH
  • 39
  • 8