brew install doesn't link python3
Question:
I’m having trouble linking python3 and making python3 the default python.
MacOS 10.13.6
Here’s what I did:
$ python --version
Python 2.7.15
$ python3 --version
Python 3.7.0
$ xcode-select --version
xcode-select version 2349.
$ brew install python
...
Python has been installed as
/usr/local/bin/python3
Unversioned symlinks `python`, `python-config`, `pip` etc. pointing to
`python3`, `python3-config`, `pip3` etc., respectively, have been installed into
/usr/local/opt/python/libexec/bin
...
It doesn’t work. python
is still 2.*
$ python --version
Python 2.7.15
$ python3 --version
Python 3.7.0
$ pip --version
pip 10.0.1 from /usr/local/lib/python2.7/site-packages/pip (python 2.7)
$ pip3 --version
pip 18.0 from /usr/local/lib/python3.7/site-packages/pip (python 3.7)
So I did:
$ brew link python3
Warning: Already linked: /usr/local/Cellar/python/3.7.0
To relink: brew unlink python && brew link python
$ python --version
Python 2.7.15
$ brew install python3
...
Warning: python 3.7.0 is already installed and up-to-date
To reinstall 3.7.0, run `brew reinstall python`
$ brew reinstall python
Also doesn’t work
$ brew link python3
Warning: Already linked: /usr/local/Cellar/python/3.7.0
To relink: brew unlink python && brew link python
$ python --version
Python 2.7.15
$ python3 --version
Python 3.7.0
Answers:
I presume you mean that you want the command python
to start the Python3 interpreter, and pip
to start pip3
.
The clue is in the message:
Unversioned symlinks python
, python-config
, pip
etc. pointing to
python3
, python3-config
, pip3
etc., respectively, have been installed into
/usr/local/opt/python/libexec/bin
That means… “if you want the command python
to start python3
and pip
to start pip3
, you need to put /usr/local/opt/python/libexec/bin
at the start of your PATH.”
So, in your login script ($HOME/.profile
or similar), you need to put:
export PATH=/usr/local/opt/python/libexec/bin:$PATH
Then log out and log back in for it to take effect.
As an aside, brew link python3
only means… “create a symbolic link in /usr/local/bin/python3
that points to /usr/local/Cellar/python/3.7.0/python3
“.
You can see that link, and where it points to, with:
ls -l /usr/local/bin/python3
At least for python 3.6 the selected answer appears to be incorrect.
It may depend on whether you have multiple python versions brew installed.
In my case i have 3.6, 3.7, 3.8, and 3.9.
so, you
brew unlink [email protected]
brew link [email protected]
after which:
- there is no entry /usr/local/opt/python
- there is no entry /usr/local/bin/python3
brew link python3
links the most recent python install (3.9 in my case) regardless of the brew link [email protected] issued earlier so it is not useful.
There is an entry /usr/local/bin/python3.6 and there is a symbolic link
/usr/local/bin/python -> python3 but NO /usr/local/bin/python3 entry.
so if you
ln -s /usr/local/bin/python3.6 python3
you will be good to go.
I had installed python
via brew and had to follow different steps:
brew install python
Later, I needed the path to add to my $PATH as export PATH=/usr/local/opt/python/libexec/bin:$PATH
wasn’t working for me.
I ran:
brew info python
Got this:
Unversioned symlinks `python`, `python-config`, `pip` etc. pointing to
`python3`, `python3-config`, `pip3` etc., respectively, have been installed into
/opt/homebrew/opt/[email protected]/libexec/bin
And then added this to my .zshrc
file
export PATH="/opt/homebrew/opt/[email protected]/libexec/bin:$PATH"
With these steps, you have made Python 3.11 the default version on your Mac. You can now use python to refer to Python 3.11 in your terminal.
For more details, I shared the entire process in Python not found on MacOS. I hope this helps.
Make sure to reload your terminal, a fancy way to do that is by running:
exec $SHELL -l
I’m having trouble linking python3 and making python3 the default python.
MacOS 10.13.6
Here’s what I did:
$ python --version
Python 2.7.15
$ python3 --version
Python 3.7.0
$ xcode-select --version
xcode-select version 2349.
$ brew install python
...
Python has been installed as
/usr/local/bin/python3
Unversioned symlinks `python`, `python-config`, `pip` etc. pointing to
`python3`, `python3-config`, `pip3` etc., respectively, have been installed into
/usr/local/opt/python/libexec/bin
...
It doesn’t work. python
is still 2.*
$ python --version
Python 2.7.15
$ python3 --version
Python 3.7.0
$ pip --version
pip 10.0.1 from /usr/local/lib/python2.7/site-packages/pip (python 2.7)
$ pip3 --version
pip 18.0 from /usr/local/lib/python3.7/site-packages/pip (python 3.7)
So I did:
$ brew link python3
Warning: Already linked: /usr/local/Cellar/python/3.7.0
To relink: brew unlink python && brew link python
$ python --version
Python 2.7.15
$ brew install python3
...
Warning: python 3.7.0 is already installed and up-to-date
To reinstall 3.7.0, run `brew reinstall python`
$ brew reinstall python
Also doesn’t work
$ brew link python3
Warning: Already linked: /usr/local/Cellar/python/3.7.0
To relink: brew unlink python && brew link python
$ python --version
Python 2.7.15
$ python3 --version
Python 3.7.0
I presume you mean that you want the command python
to start the Python3 interpreter, and pip
to start pip3
.
The clue is in the message:
Unversioned symlinks
python
,python-config
,pip
etc. pointing to
python3
,python3-config
,pip3
etc., respectively, have been installed into
/usr/local/opt/python/libexec/bin
That means… “if you want the command python
to start python3
and pip
to start pip3
, you need to put /usr/local/opt/python/libexec/bin
at the start of your PATH.”
So, in your login script ($HOME/.profile
or similar), you need to put:
export PATH=/usr/local/opt/python/libexec/bin:$PATH
Then log out and log back in for it to take effect.
As an aside, brew link python3
only means… “create a symbolic link in /usr/local/bin/python3
that points to /usr/local/Cellar/python/3.7.0/python3
“.
You can see that link, and where it points to, with:
ls -l /usr/local/bin/python3
At least for python 3.6 the selected answer appears to be incorrect.
It may depend on whether you have multiple python versions brew installed.
In my case i have 3.6, 3.7, 3.8, and 3.9.
so, you
brew unlink [email protected]
brew link [email protected]
after which:
- there is no entry /usr/local/opt/python
- there is no entry /usr/local/bin/python3
brew link python3
links the most recent python install (3.9 in my case) regardless of the brew link [email protected] issued earlier so it is not useful.
There is an entry /usr/local/bin/python3.6 and there is a symbolic link
/usr/local/bin/python -> python3 but NO /usr/local/bin/python3 entry.
so if you
ln -s /usr/local/bin/python3.6 python3
you will be good to go.
I had installed python
via brew and had to follow different steps:
brew install python
Later, I needed the path to add to my $PATH as export PATH=/usr/local/opt/python/libexec/bin:$PATH
wasn’t working for me.
I ran:
brew info python
Got this:
Unversioned symlinks `python`, `python-config`, `pip` etc. pointing to
`python3`, `python3-config`, `pip3` etc., respectively, have been installed into
/opt/homebrew/opt/[email protected]/libexec/bin
And then added this to my .zshrc
file
export PATH="/opt/homebrew/opt/[email protected]/libexec/bin:$PATH"
With these steps, you have made Python 3.11 the default version on your Mac. You can now use python to refer to Python 3.11 in your terminal.
For more details, I shared the entire process in Python not found on MacOS. I hope this helps.
Make sure to reload your terminal, a fancy way to do that is by running:
exec $SHELL -l