Search code examples
pythonpython-3.xmacospipupdates

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


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?


Solution

  • 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