macOS下通过Homebrew安装PROS CLI时遭遇pyzmq legacy-install-failure错误
问题描述
在macOS上按官方指引完成所有前置步骤后,执行brew install pros-cli时遇到pyzmq安装失败的legacy-install-failure错误,此前通过VS Code扩展安装PROS CLI的尝试也失败,网上通用的legacy-install-failure解决方法均无效。错误日志关键内容如下:
Last 15 lines from /Users/***/Library/Logs/Homebrew/pros-cli/13.pip:
exec(compile(setup_py_code, filename, "exec"))
'"'""'"'"'"'" % ('"'""'/private/tmp/pros-cli--pyzmq-20230401-14633-yuj94s/pyzmq-20.0.0/setup.py'"'"',), "", "exec"))' install --record /private/tmp/pip-record-74volvcf/install-record.txt --single-version-externally-managed --compile --install-headers /opt/homebrew/Cellar/pros-cli/3.4.1/libexec/include/site/python3.11/pyzmq
cwd: /private/tmp/pros-cli--pyzmq-20230401-14633-yuj94s/pyzmq-20.0.0/
Running setup.py install for pyzmq: finished with status 'error'
error: legacy-install-failure× Encountered error while trying to install package.
╰─> pyzmqnote: This is an issue with the package mentioned above, not pip.
hint: See above for output from the failure.[notice] A new release of pip available: 22.3.1 -> 23.0.1
[notice] To update, run: python3.11 -m pip install --upgrade pip
针对性解决步骤
优先安装pyzmq预编译二进制包
跳过源码编译,直接安装pyzmq的wheel包:pip3 install --upgrade pip setuptools wheel pip3 install pyzmq==20.0.0 --only-binary :all:完成后重新执行
brew install pros-cli补全编译依赖
pyzmq源码编译需要Xcode工具链和zmq基础库,执行以下命令安装:xcode-select --install brew install pkg-config libzmq配置环境变量让pip识别依赖:
export PKG_CONFIG_PATH="/opt/homebrew/lib/pkgconfig"再尝试安装pros-cli
切换兼容的Python版本
日志显示使用Python3.11,而pyzmq 20.0.0与该版本兼容性较差,切换到Python3.10尝试:brew install python@3.10 brew link python@3.10 --force重新执行
brew install pros-cli绕过Homebrew直接安装
如果上述方法都无效,直接用pip安装官方完整包:pip3 install pros-cli[all]安装完成后验证:
pros --version
内容的提问来源于stack exchange,提问作者gamingcomplex

