Can't update Python from 3.6 to 3.7 in MacOS

谁说胖子不能爱 提交于 2020-02-22 07:01:00

问题


I have tried several commands to update python 3.6 to python 3.7 in homebrew on MacOS.

I have tried (as administrator user):

brew update

This claimed to install python 3.7

brew upgrade

brew link python3    

brew link --overwrite python3

brew unlink python && brew link python

brew switch python 3.7.0

brew switch python 3.7.5
Cleaning /usr/local/Cellar/python/3.7.5
24 links created for /usr/local/Cellar/python/3.7.5

After all those attempts, I still get this: python3 --version Python 3.6.5

Can someone please help me to get switched over to python3?


回答1:


The final solution was that Python 3.7 was already installed and could be accessed using the command python3.7.




回答2:


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 have to remove it by explicitly setting the full PATH in your .bash_profile.

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


来源:https://stackoverflow.com/questions/58774768/cant-update-python-from-3-6-to-3-7-in-macos

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!