无法通过MacOS上的pip安装安装psycopg2软件包

2024-06-16 11:05:42 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在为我的一次讲座做一个项目,我需要下载psycopg2包,以便使用正在使用的postgresql数据库。不幸的是,当我尝试pip安装psycopg2时,会弹出以下错误:

ld: library not found for -lssl
clang: error: linker command failed with exit code 1 (use -v to see invocation)
error: command '/usr/bin/clang' failed with exit status 1
ld: library not found for -lssl
clang: error: linker command failed with exit code 1 (use -v to see invocation)
error: command '/usr/bin/clang' failed with exit status 1

有人知道为什么会这样吗?提前谢谢


Tags: forwithlibraryexitnotcodeerrorpsycopg2
3条回答
brew install postgresql

如果存在postgresql,则运行:

brew upgrade postgresql
sudo pip install psycopg2

在venv:

env LDFLAGS='-L/usr/local/lib -L/usr/local/opt/openssl/lib -L/usr/local/opt/readline/lib' pip install psycopg2==2.8.4

如果只需要使用命令pip install psycopg2在macOSX中导出路径:

export LDFLAGS="-I/usr/local/opt/openssl/include -L/usr/local/opt/openssl/lib"

请尝试使用以下工具安装它:

pip install psycopg2-binary

我通过安装命令行工具解决了这个问题

xcode-select --install

然后通过自制安装openssl并手动将自制安装的openssl链接到pip:

env LDFLAGS="-I/usr/local/opt/openssl/include -L/usr/local/opt/openssl/lib" pip install psycopg2

关于macOS Sierra 10.12.1

相关问题 更多 >