Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

brew install doesn't link python3

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
like image 545
Viet Avatar asked Aug 16 '18 21:08

Viet


People also ask

Where does Homebrew install Python on Mac?

For brewed Python, modules installed with pip or python3 setup.py install will be installed to the $(brew --prefix)/lib/pythonX. Y/site-packages directory (explained above).


1 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
like image 66
Mark Setchell Avatar answered Sep 24 '22 01:09

Mark Setchell