在 M1 mac 上导入 psycopg2 时出错:架构不兼容

问题描述 投票:0回答:4

当我尝试导入 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)

有谁知道如何解决这个错误?

python macos psycopg2 apple-m1
4个回答
30
投票

我在某些 Postgres 升级中遇到了同样的问题。重新安装

psycopg2-binary
解决了这个问题,因为这对我来说是一个缓存问题。

pip install psycopg2-binary --force-reinstall --no-cache-dir

7
投票

适用于 Mac M1 用户;

pip install -i https://test.pypi.org/simple/ psycopg2-binary==2.9.3

这样就可以解决问题了。

谢谢


3
投票

https://github.com/PostgresApp/PostgresApp/issues/83#issuecomment-1232400894

ln -s /opt/homebrew/opt/postgresql/lib/postgresql@14/* /opt/homebrew/opt/postgresql/lib/

为我工作


0
投票

卸载软件包-x86_64:

arch -x86_64 python3 -pip 卸载 psycopg2-binary

安装软件包-arm64:

arch -arm64 python3 -m pip install psycopg2-binary

© www.soinside.com 2019 - 2024. All rights reserved.