在 macOS Mojave 上安装 Python3 时出错

在 macOS Mojave 上安装 Python3 时出错

我正在尝试在运行 macOS Mojave 的 Mac 上安装 python3,但遇到了麻烦。首先,我更新了 homebrew 并运行了命令 xcode-select --install。然后,我运行了命令 brew install python3。现在,我收到此错误。

Updating Homebrew...
==> Downloading https://homebrew.bintray.com/bottles/python-3.7.3.mojave.bottle.
==> Downloading from https://akamai.bintray.com/25/25e0099852136c4ef1efd221247d0
######################################################################## 100.0%
==> Pouring python-3.7.3.mojave.bottle.tar.gz
Error: The `brew link` step did not complete successfully
The formula built, but is not symlinked into /usr/local
Could not symlink bin/2to3
Target /usr/local/bin/2to3
already exists. You may want to remove it:
  rm '/usr/local/bin/2to3'

To force the link and overwrite all conflicting files:
  brew link --overwrite python

To list all files that would be deleted:
  brew link --overwrite --dry-run python

Possible conflicting files are:
/usr/local/bin/2to3 -> /Library/Frameworks/Python.framework/Versions/3.6/bin/2to3
==> /usr/local/Cellar/python/3.7.3/bin/python3 -s setup.py --no-user-cfg install
==> /usr/local/Cellar/python/3.7.3/bin/python3 -s setup.py --no-user-cfg install
==> /usr/local/Cellar/python/3.7.3/bin/python3 -s setup.py --no-user-cfg install
==> 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

See: https://docs.brew.sh/Homebrew-and-Python
==> Summary

答案1

通过 Homebrew 安装 Python 可能会遇到麻烦。我认为更好的方法是从官方 Python 网页下载 Python:https://www.python.org/downloads/mac-osx/

下载“macOS 64 位安装程序”并使用下载的文件启动安装过程。这将自动在您的 .bash_profile 中生成正确的 PATH。

顺便说一下,这是必要的 PATH(在 .bash_profile 中):

导出 PATH="/Library/Frameworks/Python.framework/Versions/3.7/bin:${PATH}"

相关内容