Home > Back-end >  Unable to install Python 3 on OSX 10.2
Unable to install Python 3 on OSX 10.2

Time:09-17

I had some issues with installing Python 3 on my Mac with OSX 10.12. Now I have stuck on point when Python is installed but is not properly linked.

I installed it via homebrew by brew install [email protected] and command python3 gives me

pavelprdel@Pavels-Mac-mini ~ % python3
Python 3.9.7 (default, Sep  3 2021, 04:31:11) 
[Clang 12.0.5 (clang-1205.0.22.9)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

But with command python I get

pavelprdel@Pavels-Mac-mini ~ % python
zsh: no such file or directory: /usr/local/bin/python3.9.7
pavelspurny@Pavels-Mac-mini ~ % 

I have found solution via brew link --overwrite python command but I only get this

Warning: Already linked: /opt/homebrew/Cellar/python@3.9/3.9.7
To relink, run:
  brew unlink python@3.9 && brew link python@3.9

And relink doesn't work, I used which python command and it seems that it is installed in different location

python: aliased to /usr/local/bin/python3.9.7 

I have also installed python from https://www.python.org/ but result is still the same.

CodePudding user response:

Just link it manually:

# remove current link
unlink /usr/local/bin/python

# add new link
ln -s $(which python3) /usr/local/bin/python

Also check $PATH variable:

echo ${PATH}

...:/usr/local/bin:/usr/bin:/bin:/usr/sbin:...

/usr/local/bin must prepend /usr/bin because here is default python 2.x interpreter /usr/bin/python and /usr/local/bin/python must be called first

Also I don't recommend to override system's /usr/bin/python with python3, it should be reverted if already overridden

Check for upvoted 41 times warning (However that is not a so big problem for mac OS in compare to Linux OS):

Just a warning: Do not attempt to change the /usr/bin/python symlink to point to python3 instead of 2.7. Many programs available in the Ubuntu repos require /usr/bin/python to be compatible to python 2.x.

Anyway usually the python is used to run python 2.x and the python3 to run python 3.x. I recommend to use pyenv (for shell session scope) or virtualenv (for project scope) to be able override python with python3 only where it needed.

In other cases execute python 3 via python3 command is a normal practice

CodePudding user response:

A better way to install python is by downloading it from the following link: https://www.python.org/. Then, click on the download tab and select the newest version. This should fix your problem. Installing via brew might be outdated and does not always work on OSX.

  • Related