Homebrew 安装后无法运行 Python 3

新手上路,请多包涵

使用主页上的脚本安装 Homebrew 并使用 brew doctor 检查是否一切正常后,我发布了 brew install python3 以便在我的 Mac 上安装 Python 3。

一切似乎都很好,直到我尝试运行 python3 --version ;我最终得到:

-bash: /Library/Frameworks/Python.framework/Versions/3.5/bin/python3: No such file or directory

我检查了文件目录以查看发生了什么,实际上,我没有在我的框架文件夹中看到任何与 Python 相关的文件。看起来 Python 2.7 也不在我的 Mac 上。

这是我安装 Python 3 后得到的:

Summary 🍺 /usr/local/Cellar/python3/3.5.1: 3,438 files, 51.5M

edit_2:也许这与没有 Python 框架有关?我刚从 Python 网站上读到这个:

Apple 提供的 Python 版本分别安装在 /System/Library/Frameworks/Python.framework 和 /usr/bin/python 中。你不应该修改或删除这些,因为它们是由 Apple 控制的,并由 Apple 或第三方软件使用。请记住,如果您选择从 python.org 安装较新的 Python 版本,您的计算机上将安装两个不同但功能正常的 Python,因此您的路径和用法与您想要执行的操作一致非常重要。

原文由 vcyf56rtrfc 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 2.3k
2 个回答

好的,这是我收集的:

原文由 vcyf56rtrfc 发布,翻译遵循 CC BY-SA 3.0 许可协议

我想我发现了问题所在。

我猜想,在某个时刻,您是从官方网站而不是通过 Homebrew 安装 python 的。就我而言,我是通过官方网站安装的 Python 3.6.4 。几个月后,我想升级它,发现它非常复杂。所以,我决定转向 Homebrew。打开一个终端窗口,让我们尝试解决这个问题:

  1. 首先,让我们卸载以前的 Python 版本:
     sudo rm -rf /Library/Frameworks/Python.framework
    sudo rm -rf /usr/local/bin/python3

  1. 然后,从 $PATH 变量中删除以前的框架:
     nano ~/.bash_profile

你会看到类似的东西:

     # Setting PATH for Python 2.7
    # The original version is saved in .bash_profile.pysave
    PATH="/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}"
    export PATH

    # Setting PATH for Python 3.6
    # The original version is saved in .bash_profile.pysave
    PATH="/Library/Frameworks/Python.framework/Versions/3.6/bin:${PATH}"
    export PATH`

这就是问题所在:这些路径不存在。评论 $PATH editions (或擦除它们):

     # Setting PATH for Python 2.7
    # The original version is saved in .bash_profile.pysave
    # PATH="/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}"
    # export PATH

    # Setting PATH for Python 3.6
    # The original version is saved in .bash_profile.pysave
    # PATH="/Library/Frameworks/Python.framework/Versions/3.6/bin:${PATH}"
    # export PATH

  1. 重新启动计算机并通过 Homebrew Python 2 和 3 安装:
     brew update
    brew install python
    brew install python3

这对我有用。现在,如果键入 python3 --version 我得到 Python 3.7.0 ,一切正常:)

原文由 Román Cárdenas 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题