I've gone through a number of these, and I think for those who are unresolved otherwise should take a look at the potential problem. I'm guessing many people are coming from M1 Macs, and may or may not have Postgres.app installed.
If you add -v
to the end of your pip3 install psycopg2
, then you'll see the source of the error towards the bottom. In my case I got:
ld: warning: ignoring file /Applications/Postgres.app/Contents/Versions/14/lib/libcrypto.dylib, file is universal (x86_64,arm64) but does not contain the arm64e architecture: /Applications/Postgres.app/Contents/Versions/14/lib/libcrypto.dylib
ld: warning: ignoring file /Applications/Postgres.app/Contents/Versions/14/lib/libpq.dylib, file is universal (x86_64,arm64) but does not contain the arm64e architecture: /Applications/Postgres.app/Contents/Versions/14/lib/libpq.dylib
ld: warning: dylib (/Applications/Postgres.app/Contents/Versions/14/lib/libssl.dylib) was built for newer macOS version (10.12) than being linked (10.9)
ld: warning: ld: warning: dylib (/Applications/Postgres.app/Contents/Versions/14/lib/libpq.dylib) was built for newer macOS version (10.12) than being linked (10.9)
dylib (/Applications/Postgres.app/Contents/Versions/14/lib/libcrypto.dylib) was built for newer macOS version (10.12) than being linked (10.9)
Here we can see that the lack of arm64e architecture in the libpq libraries is the root cause.
To fix this, specify that you only want arm64, as that's what's available in libpq.
ARCHFLAGS="-arch arm64" pip3 install psycopg2 --no-cache-dir --force-reinstall -v
If your warnings are different, then this advice won't apply but it should give you some clues as to what's happening. The warning about being built for a newer build of macOS shouldn't break things. Ignoring the libpq libraries should really be an error versus a warning here.