python - Homebrew 安装后无法运行 Python 3

标签 python macos python-3.x terminal homebrew

使用主页上的脚本安装 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 网站上读到了这个:

The Apple-provided build of Python is installed in /System/Library/Frameworks/Python.framework and /usr/bin/python, respectively. You should never modify or delete these, as they are Apple-controlled and are used by Apple- or third-party software. Remember that if you choose to install a newer Python version from python.org, you will have two different but functional Python installations on your computer, so it will be important that your paths and usages are consistent with what you want to do.

最佳答案

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

  • 首先,让我们卸载以前的 Python 版本:
     sudo rm -rf /Library/Frameworks/Python.framework
     sudo rm -rf /usr/local/bin/python3
    
  • 然后,从 $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
    
  • 重新启动计算机并通过 Homebrew Python 2 和 3 安装:
     brew update
     brew install python
     brew install python3
    

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

    关于python - Homebrew 安装后无法运行 Python 3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36001966/

    相关文章:

    python - 在绘制 3d 表面时摆脱伪影/网格线

    java - Macos系统菜单名称带/Java?

    objective-c - 在 10.10 Yosemite 中禁用/自定义 NSPopUpButton 动画

    mysql - 在 MySQL Workbench 中查看长错误响应

    python-3.x - 双线性四边形插值的Python实现

    python - 重新评估 Python 正则表达式中的字符

    python - 在 while 循环之外访问变量,Python

    javascript - Django 单选按钮

    javascript - JSONify 返回奇怪的值

    python - 通过将列表相乘来创建列表的列表意外地使内部列表保持连接