Can't update Python from 3.6 to 3.7 in MacOS
Based on the comment:
which python3 -> /Library/Frameworks/Python.framework/Versions/3.6/bin/python3
Your python3
is not the same one installed/managed by Homebrew.
(Maybe it's from a Python .pkg installer for Mac?).
First, install it via Homebrew:
$ brew uninstall python3 # let's start from scratch
$ brew install python3
Check where it's installed:
$ brew info python3
python: stable 3.7.5 (bottled), HEAD
...
==> Caveats
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
If you need Homebrew's Python 2.7 run
brew install python@2
You can install Python packages with
pip3 install <package>
They will install into the site-package directory
/usr/local/lib/python3.7/site-packages
...
Notice that Homebrew installed it at /usr/local/bin/python3 and the site-packages are stored at the corresponding /usr/local/lib/python3.7/site-packages.
Next, you need to make sure your OS looks for python3
at that same path.
$ echo $PATH
/usr/local/sbin:/usr/local/opt/openssl/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
If you don't see /usr/local/bin there, add it to your PATH
by adding this to your ~/.bash_profile:
export PATH=/usr/local/bin:$PATH
Then source
the updated ~/.bash_profile (or restart your Terminal).
$ source ~/.bash_profile
$ echo $PATH
From the comment, if your PATH
shows /Library/Frameworks/Python.framework/Versions/3.6/bin/python3, you'll either have to remove it by explicitly setting the full PATH
in your .bash_profile or make sure it comes after Homebrew's Python in /usr/local/bin.
Finally, check that python3
is now correct:
$ which python3
/usr/local/bin/python
$ ls -l /usr/local/bin/python
lrwxr-xr-x 1 gino admin 38 Oct 4 17:35 /usr/local/bin/python3 -> ../Cellar/python/3.7.5/bin/python3
$ python3 -V
Python3.7.5
Notice that python3
should be the python3
installed by Homebrew in the ../Cellar directory.
Can I easily change to the homebrew installation, or will I lose all my installed packages?
I would recommend re-installing the packages over at Homebrew's python3
's site-packages folder. If you maintained a requirements.txt file for your Python projects, it's as simple as:
$ python3 -m pip install -r requirements.txt
The final solution was that Python 3.7 was already installed and could be accessed using the command python3.7
.