tobemaster56 / draft

记录开发过程中遇到的问题
MIT License
5 stars 0 forks source link

为什么 macOS 在 /usr/bin/ 下会有 python3? #131

Open tobemaster56 opened 11 months ago

tobemaster56 commented 11 months ago

今天准备尝试 open interpreter,https://github.com/KillianLucas/open-interpreter/ 官方的安装方式是:pip install open-interpreter, 因为我系统装的是 python3 和 pip3,所以我执行的是 pip3 install open-interpreter 执行第一步安装就卡住了,命令报错,我的设备是 Mac studio,系统版本是 13.2.1

image
Defaulting to user installation because normal site-packages is not writeable
ERROR: Could not find a version that satisfies the requirement open-interpreter (from versions: none)
ERROR: No matching distribution found for open-interpreter
WARNING: You are using pip version 21.2.4; however, version 23.2.1 is available.
You should consider upgrading via the '/Library/Developer/CommandLineTools/usr/bin/python3 -m pip install --upgrade pip' command.

一开始,我是以为python3 的版本不对,想要重新安装 python,所以我先卸载再说,我先执行的是 brew uninstall python3,提示不存在,我就纳闷了,python3 不是通过 brew 安装的吗? which python3,发现是在 /usr/bin/python3下,但我完全不记得是怎么安装 python3 的了,在网上搜索了一番之后,

https://www.zhihu.com/question/420273182

/usr/bin/python3 这个应该是系统内置的,在安装了 CommandLineTools 之后,指向的是 /Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework,具体版本是 python@3.9.6

网上说了,可以通过删除CommandLineTools,来删除系统自带的 python3,但是不建议删除 我然后从 brew上安装了另外版本的 python@3.11,安装的命令也叫 python3 和 pip3,当我执行 python3 --version,显示的是 3.9.6,于是我执行

type -a python3
python3 is /opt/homebrew/bin/python3
python3 is /usr/bin/python3

发现 brew 安装的 path 在前,这就奇怪了,因为不符合 path 寻找的规律,先找到谁就用谁 我不想删除系统自带的,于是想到了另外一个办法,既然重名了,就另外起个别名呗,在.zshrc 中加入

alias python="/opt/homebrew/bin/python3"
alias pip="/opt/homebrew/bin/pip3"

然后,在终端中执行 python --version,终于看到了想到的结果,结果更神奇的是,执行which python3,也指向了 /opt/homebrew/bin/python3,即便我把刚刚起的别名注释掉,python3 指向的仍然是/opt/homebrew/bin/python3,终于感觉一切正常了