[英]Mac OS X Lion Psycopg2: Symbol not found: _PQbackendPID
[英]Psycopg2 error: Symbol not found _PQbackendPID
我从 psycopg2 收到以下错误:
Traceback (most recent call last): File "test1.py", line 1, in
<module>
import psycopg2 File "/Users/xxx/Library/Python/2.7/lib/python/site-packages/psycopg2/__init__.py",
line 50, in <module>
from psycopg2._psycopg import ( # noqa ImportError:
dlopen(/Users/xxx/Library/Python/2.7/lib/python/site-packages/psycopg2/_psycopg.so,
2): Symbol not found: _PQbackendPID Referenced from:
/Users/xxx/Library/Python/2.7/lib/python/site-packages/psycopg2/_psycopg.so
Expected in: flat namespace in
/Users/eyabadal/Library/Python/2.7/lib/python/site-packages/psycopg2/_psycopg.so
对于如何解决这个问题,有任何的建议吗?
我在 macOS 上遇到了同样的问题,并通过运行以下步骤解决了它:
我遇到了同样的问题,使用选项--no-cache-dir
安装psycopg2-binary
对我有帮助。
pip install psycopg2-binary --no-cache-dir
致那些还在挣扎的人
您是否正在使用 PyCharm 创建 venv?
这就是我的问题。 我删除了 pycharm 创建的 venv,然后使用python3 -m venv /path/to/venv
手动创建它,然后激活pip3 install -r requirements.txt
运行完美
以上答案均不适用于 python 3.8 版本。 我不得不升级到 python 3.9 并且错误消失了。 - 我有带 M1 PRO 芯片的 12.4 macOS
对于仍然有问题的任何人,我使用了以下方法:
pip install -i https://test.pypi.org/simple/ psycopg2-binary==2.9.3
你可以在这里找到评论: https://github.com/psycopg/psycopg2/issues/1286#issuecomment-1190350326
我已经经历了其中的一些,我认为对于那些没有解决的人应该看看潜在的问题。 我猜很多人都来自 M1 Mac,可能安装了也可能没有安装 Postgres.app。
如果您将-v
添加到pip3 install psycopg2
的末尾,那么您将在底部看到错误的来源。 就我而言,我得到了:
ld: warning: ignoring file /Applications/Postgres.app/Contents/Versions/14/lib/libcrypto.dylib, file is universal (x86_64,arm64) but does not contain the arm64e architecture: /Applications/Postgres.app/Contents/Versions/14/lib/libcrypto.dylib
ld: warning: ignoring file /Applications/Postgres.app/Contents/Versions/14/lib/libpq.dylib, file is universal (x86_64,arm64) but does not contain the arm64e architecture: /Applications/Postgres.app/Contents/Versions/14/lib/libpq.dylib
ld: warning: dylib (/Applications/Postgres.app/Contents/Versions/14/lib/libssl.dylib) was built for newer macOS version (10.12) than being linked (10.9)
ld: warning: ld: warning: dylib (/Applications/Postgres.app/Contents/Versions/14/lib/libpq.dylib) was built for newer macOS version (10.12) than being linked (10.9)
dylib (/Applications/Postgres.app/Contents/Versions/14/lib/libcrypto.dylib) was built for newer macOS version (10.12) than being linked (10.9)
在这里我们可以看到libpq库中缺少arm64e架构是根本原因。
要解决此问题,请指定您只需要 arm64,因为这是 libpq 中可用的。
ARCHFLAGS="-arch arm64" pip3 install psycopg2 --no-cache-dir --force-reinstall -v
如果您的警告不同,则此建议将不适用,但它应该为您提供一些关于正在发生的事情的线索。 关于为更新版本的 macOS 构建的警告不应该破坏事情。 忽略 libpq 库实际上应该是一个错误而不是这里的警告。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.