MacOS虚拟环境安装psycopg2/psycopg2-binary失败求助
MacOS虚拟环境安装psycopg2/psycopg2-binary失败求助
嘿,我在MacOS的虚拟环境里执行pip3 install psycopg2-binary时一直碰到报错,具体错误信息如下:
(env) macbook@MACBOOKs-MacBook-Pro server % pip3 install psycopg2-binary Collecting psycopg2-binary Using cached psycopg2-binary-2.9.10.tar.gz (385 kB) Installing build dependencies ... done Getting requirements to build wheel ... error error: subprocess-exited-with-error × Getting requirements to build wheel did not run successfully. │ exit code: 1 ╰─> [34 lines of output] /private/var/folders/mf/mmt_x2rn2fn7cx10vy7r7nl0000...(后续输出未完整粘贴,但核心问题为构建wheel失败)
有没有大佬能帮忙支招解决呀?我自己试了几个方向,也想听听大家的其他建议:
- 先确认Xcode命令行工具是否安装:执行
xcode-select --install,如果提示已安装就跳过,未安装的话完成安装后重试 - 升级pip、setuptools和wheel,旧版本可能存在兼容性问题:
pip install --upgrade pip setuptools wheel - 通过Homebrew安装PostgreSQL依赖,psycopg2需要依赖PostgreSQL的底层库:
brew install postgresql,安装完成后再重新执行psycopg2-binary的安装命令 - 检查虚拟环境状态:有时候环境激活异常或者本身有问题,可尝试重建虚拟环境:
deactivate rm -rf env python3 -m venv env source env/bin/activate pip install psycopg2-binary
如果这些方法都没解决,能不能帮我看看错误输出里的完整日志?比如那34行内容里有没有提到具体缺失的依赖或者其他关键错误提示?
备注:内容来源于stack exchange,提问作者RakutenSTD




