无法通过pip安装安装psycopg2包。。。是因为塞拉吗?

2024-04-29 01:01:04 发布

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

我正在为我的一个讲座做一个项目,我需要下载psycopg2包才能使用postgresql数据库。不幸的是,当我尝试pip install 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

有人知道为什么会这样吗?是因为Sierra不支持某些包吗?提前谢谢!


Tags: forwithlibraryexitnotcodeerrorpsycopg2
3条回答

请尝试使用以下命令安装它:

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上

  1. 安装/更新Xcode开发工具

    xcode-select --install
    
  2. 查询postgres路径

    find / -name pg_config  2>/dev/null
    
  3. 安装psycopg2,使用步骤2中的路径。我的是'/usr/local/cell/postgresql/9.5.0/bin/pg_config'

    PATH=$PATH:/usr/local/Cellar/postgresql/9.5.0/bin/ pip install psycopg2
    

相关问题 更多 >