在MacOS中无法将Python从3.6更新到3.7

时间:2019-11-08 23:01:10

标签: python-3.x homebrew updates

我已经尝试了一些命令,以在MacOS上的自制软件中将python 3.6更新为python 3.7。

我已经尝试过(作为管理员用户):

brew update

这声称安装了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

经过所有这些尝试,我仍然得到以下信息:     python3-版本     Python 3.6.5

有人可以帮我切换到python3吗?

2 个答案:

答案 0 :(得分:2)

基于comment

  

which python3 -> /Library/Frameworks/Python.framework/Versions/3.6/bin/python3

您的python3与Homebrew安装/管理的不是同一个人。
(也许是来自Python .pkg installer for Mac的吗?)。

首先,通过Homebrew安装它:

$ brew uninstall python3   # let's start from scratch
$ brew install python3

检查安装位置:

$ 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
...

请注意,Homebrew将其安装在 / usr / local / bin / python3 上,并且站点软件包存储在相应的 /usr/local/lib/python3.7/site-包

接下来,您需要确保您的操作系统在同一路径下寻找python3

$ echo $PATH
/usr/local/sbin:/usr/local/opt/openssl/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

如果在此处看不到 / usr / local / bin ,请将其添加到您的PATH中,方法是将其添加到您的〜/ .bash_profile 中:

export PATH=/usr/local/bin:$PATH

然后source更新更新的〜/ .bash_profile (或重新启动终端)。

$ source ~/.bash_profile
$ echo $PATH

comment中,如果您的PATH显示 /Library/Frameworks/Python.framework/Versions/3.6/bin/python3 ,则必须将其删除通过在您的 .bash_profile 中明确设置完整的PATH

最后,检查python3现在是否正确:

$ 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

请注意,python3应该是Homebrew在 ../ Cellar 目录中安装的python3

  

我可以轻松更改为自制软件安装,还是会丢失所有已安装的软件包?

我建议在Homebrew的python3 site-packages 文件夹中重新安装软件包。如果您为Python项目维护了一个 requirements.txt 文件,则该过程非常简单:

$ python3 -m pip install -r requirements.txt

答案 1 :(得分:2)

最终的解决方案是已经安装了Python 3.7,可以使用命令python3.7进行访问。