使用主页上的脚本安装 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。打开一个终端窗口,让我们尝试解决这个问题:
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
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/