无法在 MacOS 中将 Python 从 3.6 更新到 3.7
Can't update Python from 3.6 to 3.7 in MacOS
我尝试了几个命令将 python 3.6 更新为 python 3.7 在 MacOS 上的自制软件中。
我试过(作为管理员用户):
brew update
这个声称要安装python3.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 --版本
Python3.6.5
有人可以帮我切换到 python3 吗?
基于:
which python3 -> /Library/Frameworks/Python.framework/Versions/3.6/bin/python3
您的 python3
与 Homebrew 的 installed/managed 不同。
(也许它来自 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 -包.
接下来,您需要确保您的 OS 在同一路径上查找 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
从 开始,如果您的 PATH
显示 /Library/Frameworks/Python.framework/Versions/3.6/bin/python3 ,您要么必须通过在 .bash_profile 中明确设置完整的 PATH
来删除它,要么确保它出现在 after /usr/local/bin.
中的自制软件 Python
最后,检查 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
Can I easily change to the homebrew installation, or will I lose all my installed packages?
我建议在 Homebrew 的 python3
的 site-packages 文件夹中重新安装软件包。如果您为您的 Python 项目维护一个 requirements.txt 文件,它就像:
$ python3 -m pip install -r requirements.txt
最终的解决方案是Python3.7已经安装好,可以使用python3.7
.
命令访问
我尝试了几个命令将 python 3.6 更新为 python 3.7 在 MacOS 上的自制软件中。
我试过(作为管理员用户):
brew update
这个声称要安装python3.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 --版本 Python3.6.5
有人可以帮我切换到 python3 吗?
基于
which python3 -> /Library/Frameworks/Python.framework/Versions/3.6/bin/python3
您的 python3
与 Homebrew 的 installed/managed 不同。
(也许它来自 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 -包.
接下来,您需要确保您的 OS 在同一路径上查找 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
从 PATH
显示 /Library/Frameworks/Python.framework/Versions/3.6/bin/python3 ,您要么必须通过在 .bash_profile 中明确设置完整的 PATH
来删除它,要么确保它出现在 after /usr/local/bin.
最后,检查 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
Can I easily change to the homebrew installation, or will I lose all my installed packages?
我建议在 Homebrew 的 python3
的 site-packages 文件夹中重新安装软件包。如果您为您的 Python 项目维护一个 requirements.txt 文件,它就像:
$ python3 -m pip install -r requirements.txt
最终的解决方案是Python3.7已经安装好,可以使用python3.7
.