当我尝试导入 psycopg2 时,收到此错误消息:
ImportError: dlopen(/opt/homebrew/lib/python3.10/site-packages/psycopg2/_psycopg.cpython-310-darwin.so, 0x0002): Library not loaded: /opt/homebrew/opt/postgresql/lib/libpq.5.dylib
Referenced from: /opt/homebrew/lib/python3.10/site-packages/psycopg2/_psycopg.cpython-310-darwin.so
Reason: tried: '/opt/homebrew/opt/postgresql/lib/libpq.5.dylib' (no such file), '/usr/local/lib/libpq.5.dylib' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e')), '/usr/lib/libpq.5.dylib' (no such file), '/opt/homebrew/Cellar/postgresql@14/14.5_3/lib/libpq.5.dylib' (no such file), '/usr/local/lib/libpq.5.dylib' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e')), '/usr/lib/libpq.5.dylib' (no such file)
有谁知道如何解决这个错误?
我在某些 Postgres 升级中遇到了同样的问题。重新安装
psycopg2-binary
解决了这个问题,因为这对我来说是一个缓存问题。
pip install psycopg2-binary --force-reinstall --no-cache-dir
适用于 Mac M1 用户;
pip install -i https://test.pypi.org/simple/ psycopg2-binary==2.9.3
这样就可以解决问题了。
谢谢
https://github.com/PostgresApp/PostgresApp/issues/83#issuecomment-1232400894
ln -s /opt/homebrew/opt/postgresql/lib/postgresql@14/* /opt/homebrew/opt/postgresql/lib/
为我工作
arch -x86_64 python3 -pip 卸载 psycopg2-binary
arch -arm64 python3 -m pip install psycopg2-binary