我在这个问题上停留了一段时间。努力在Mac上安装psycpg2之后,我得到了一个朋友来帮助我使用以下方法安装它:
env LDFLAGS="-I/usr/local/opt/openssl/include -L/usr/local/opt/openssl/lib" pip3 install psycopg2
然后我导入了psycopg2
我尝试运行数据库程序并收到此错误:
Traceback (most recent call last):
File "postgresdemo.py", line 1, in <module>
import psycopg2
File "/Users/nkosana/Library/Python/3.7/lib/python/site-packages/psycopg2/__init__.py", line 51, in <module>
from psycopg2._psycopg import ( # noqa
ImportError: dlopen(/Users/nkosana/Library/Python/3.7/lib/python/site-packages/psycopg2/_psycopg.cpython-37m-darwin.so, 2): Symbol not found: _PQencryptPasswordConn
Referenced from: /Users/nkosana/Library/Python/3.7/lib/python/site-packages/psycopg2/_psycopg.cpython-37m-darwin.so
Expected in: /usr/lib/libpq.5.dylib in /Users/nkosana/Library/Python/3.7/lib/python/site-packages/psycopg2/_psycopg.cpython-37m-darwin.so
系统和版本
MacOS Catalina(10.15.4)
psycopg2-2.8.5
Python 3.7.3
在此先感谢您的帮助。
答案 0 :(得分:0)
我遇到了同样的问题:
Symbol not found: _PQencryptPasswordConn
Referenced from: /Users/Lynda/pgproject/pgprojectenv/lib/python3.7/site-packages/psycopg2/_psycopg.cpython-37m-darwin.so
Expected in: /usr/lib/libpq.5.dylib
对我有用的是将/ usr / local / lib添加到PATH,并创建从我的PostgreSQL / lib到/ usr / local / lib的符号链接
cd /usr/local/lib
ln -s /Users/Lynda/PostgreSQL/lib/libpq.5.12.dylib ./libpq.5.dylib
有一个可以解决此lib错误的答案,可以更好地解释这种情况的发生原因以及如何在此处Mac OS X Lion Psycopg2: Symbol not found: _PQbackendPID
进行修复。答案 1 :(得分:0)
pip uninstall psycopg2
pip install psycopg2
来自 here,为我工作。 macOS Catalina 版本 10.15.7。 Python 3.5.9