Download the new python on MacOS but still got the old version when asking for python version

Question:

I am transforming from windows to Macos and want to install python. It came with an old version of python 2.7 in the computer, so I download python 3 using the pyenv install command. But when I input python --version, I still got the old version. Why is that? And I can’t install pip either. Anybody knows why?

Asked By: Yingqi

||

Answers:

If you have installed python 3 (check it by running python3 --version), you can set python3 as a default python version by creating a symbolic link.

run ls -l /usr/local/bin/python* to see where all versions are installed.

lrwxr-xr-x  1 root  wheel  69 May 10  2019 /usr/local/bin/python3 -> ../../../Library/Frameworks/Python.framework/Versions/3.7/bin/python3
lrwxr-xr-x  1 root  wheel  76 May 10  2019 /usr/local/bin/python3-config -> ../../../Library/Frameworks/Python.framework/Versions/3.7/bin/python3-config
lrwxr-xr-x  1 root  wheel  71 May 10  2019 /usr/local/bin/python3.7 -> ../../../Library/Frameworks/Python.framework/Versions/3.7/bin/python3.7
lrwxr-xr-x  1 root  wheel  78 May 10  2019 /usr/local/bin/python3.7-config -> ../../../Library/Frameworks/Python.framework/Versions/3.7/bin/python3.7-config
lrwxr-xr-x  1 root  wheel  72 May 10  2019 /usr/local/bin/python3.7m -> ../../../Library/Frameworks/Python.framework/Versions/3.7/bin/python3.7m
lrwxr-xr-x  1 root  wheel  79 May 10  2019 /usr/local/bin/python3.7m-config -> ../../../Library/Frameworks/Python.framework/Versions/3.7/bin/python3.7m-config

The output is like above, now you just need to choose the version you want from the ones which end with ...python3.X not ...-config or ...python3.Xm, and create a symbolic link to it.

For example, you have chosen python3.7 to run as a default version, now it’s time to create the symbolic link by running:

ln -s -f /usr/local/bin/python3.7 /usr/local/bin/python

now if you run python --version its output should be 3.7

Answered By: Threem

To add on to @Threem’s answer, if you have the same issue with pip and pip3 (python’s package manager) then you can run the following:

ls -l /usr/local/bin/pip*

You’ll see something similar to his answer, but with pip instead of python.

Then you can create a symbolic link the same way.

ln -s -f /usr/local/bin/pip3.10 /usr/local/bin/pip

Now if you run

pip --version

you’ll get your pip3 version.

If anyone gets hit with the "permission denied" error you can instead just do:

alias python=python3
Answered By: Logan Brassington