Search code examples
pythonpsycopg2

ImportError when importing psycopg2 on M1


Has anyone gotten this error when importing psycopg2 after successful installation?

ImportError: dlopen(/Users/chrishicks/Desktop/test/venv/lib/python3.9/site-packages/psycopg2/_psycopg.cpython-39-darwin.so, 0x0002):
tried: '/Users/chrishicks/Desktop/test/venv/lib/python3.9/site-packages/psycopg2/_psycopg.cpython-39-darwin.so'
(mach-o file, but is an incompatible architecture
(have 'x86_64', need 'arm64e')),
'/usr/local/lib/_psycopg.cpython-39-darwin.so' (no such file),
'/usr/lib/_psycopg.cpython-39-darwin.so' (no such file)

I have tried installing psycopg2 and psycopg2-binary and have tried both while running iTerm in Rosetta.


Solution

  • Using this line should fix it:

    pip3.9 install psycopg2-binary --force-reinstall --no-cache-dir