搞懂macOS上基于homebrew的Python多版本管理 |
您所在的位置:网站首页 › mac版本升级不了 › 搞懂macOS上基于homebrew的Python多版本管理 |
今天把Mac上的ffmpeg升级了一下 >>> brew upgrade ffmpeg谁知道新的ffmpeg依赖Python3.9 一连串依赖安装下来: 现在系统存在三个版本的Python:
参考: https://stackoverflow.com/a/38806058 如果你之前是通过get-pip.py文件安装的pip,则最好是将其卸载,因为brew安装的python已经包含pip工具 总结: 不要使用python3 get-pip.py安装pip,因为通过brew安装的python都自带pip使用brew link {python@version}管理python版本,简单高效使用docker或者venv、pyenv这些虚拟环境管理多版本如果出现: >>> brew link [email protected] Linking /usr/local/Cellar/[email protected]/3.9.1_4... Error: Could not symlink bin/pip3.9 Target /usr/local/bin/pip3.9 already exists. You may want to remove it: rm '/usr/local/bin/pip3.9' To force the link and overwrite all conflicting files: brew link --overwrite [email protected] To list all files that would be deleted: brew link --overwrite --dry-run [email protected]则按照提示删除就好了 关于系统自带的Python: macOS最开始只安装有python2.7,而在安装homebrew时会被要求安装Command Line Tools (CLT) for Xcode 参考: https://docs.brew.sh/Installation https://medium.com/faun/the-right-way-to-set-up-python-on-your-mac-e923ffe8cf8e 2022-10-27更新今天homebrew终于放出了Python3.11.0版本,准备安装尝试一下,按照往常执行如下命令 >>> brew install [email protected] >>> brew unlink [email protected] >>> brew link [email protected]但做完以后,发现执行python3命令时,出现的竟然是python3.9.6,即系统自带的Pyhton版本 进一步查看 >>> ll /usr/local/bin/python* lrwxr-xr-x 1 microfat admin 43B Oct 27 11:19 /usr/local/bin/python3.11 -> ../Cellar/[email protected]/3.11.0/bin/python3.11 lrwxr-xr-x 1 microfat admin 50B Oct 27 11:19 /usr/local/bin/python3.11-config -> ../Cellar/[email protected]/3.11.0/bin/python3.11-config lrwxr-xr-x 1 microfat admin 41B Oct 27 10:36 /usr/local/bin/python3.9 -> ../Cellar/[email protected]/3.9.15/bin/python3.9 lrwxr-xr-x 1 microfat admin 48B Oct 27 10:36 /usr/local/bin/python3.9-config -> ../Cellar/[email protected]/3.9.15/bin/python3.9-config可以看到并没有python3的软链 重复尝试多次后发现,只有brew link [email protected]时能够生效,其他版本的python都生成不了python3软链 找了很久也没查出问题原因,如果您知道,请您一定不吝赐教🙏 最后只能放弃brew link改用手动添加环境变量的方式了 >>> vim .zshrc ... export PATH="$(brew --prefix [email protected])/libexec/bin:$PATH" ... >>> source .zshrc参考:https://github.com/Homebrew/homebrew-core/issues/107904#issuecomment-1213272960 |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |