ImportError when importing psycopg2 on M1
Asked Answered
E

2

9

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.

Exercise answered 23/3, 2022 at 1:38 Comment(3)
Welcome to SO. Please clarify what operating system you're using.Hydromagnetics
How are you installing this? brew or pip? I've just tried to install with pip3 on M1 and works fine!Perpendicular
Hi @ewong thank you. I am using Monterey 12.2.1Exercise
A
35

Using this line should fix it:

pip3.9 install psycopg2-binary --force-reinstall --no-cache-dir
Ahem answered 23/3, 2022 at 2:21 Comment(3)
Of course! Anything for Hicks LLC!Ahem
no, I still have that error onlyLipscomb
Also, what is the significance of pip3.9 over any other pip.3x?Kho
L
2

my fellow had the same issue. I consoled pip3.9 install psycopg2-binary --force-reinstall --no-cache-dir but it didn't work for him. I helped him to solved it by this way: firstly, uninstall the psycopg2-binary

pip uninstall psycopg2-binary

Then, install it

pip install psycopg2-binary

@hardy

Lidless answered 16/9, 2022 at 10:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.