Open jrybinski opened 2 years ago
Same problem with the arch mismatch:
ld: warning: ignoring file /opt/homebrew/lib/postgresql@14/libpq.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64
I'm trying to build the package on an M1 Mac running the nightly version of PyPy3.9 that introduced support for M1.
There is no postgres
driver for M1 macs, but it's possible to install it under rosetta. Just ensure that during the installation from pip, it is linked with the x86_64
version of the postgres driver. If there is already an m1
driver installed into the system, you would better compile it from source for x86 and put into an isolated prefix and install psycopg2cffi
linking with the correct driver version.
An example of a script that can do this (ofk should be run in the x86_64
mode).
#!/bin/bash
if [ $# -le 0 ]; then
echo "Usage: $0 <PATH_TO_PYTHON_BIN>"
exit 1
fi
PYTHON=$1
set -ex -o pipefail
PREFIX=${HOME}/.postgresql-14.2-x86_64
curl --fail https://ftp.postgresql.org/pub/source/v14.2/postgresql-14.2.tar.bz2 -o postgresql-14.2.tar.bz2
tar xpf postgresql-14.2.tar.bz2
cd postgresql-14.2
arch -arch x86_64 ./configure --prefix=${PREFIX}
arch -arch x86_64 make
make install
${PYTHON} -mensurepip
CPPFLAGS=-I${PREFIX}/include LDFLAGS=-L${PREFIX}/lib ${PYTHON} -mpip install psycopg2cffi
Tested with pypy3.8
just now.
$ ./compile-psycopg2cffi-from-source.sh
...
Installing collected packages: six, psycopg2cffi
Running setup.py install for psycopg2cffi ... done
Successfully installed psycopg2cffi-2.9.0 six-1.16.0
$ pypy
[PyPy 7.3.9 with GCC Apple LLVM 13.1.6 (clang-1316.0.21.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>> import psycopg2cffi
>>>>
There is no postgres driver for M1 macs, but it's possible to install it under rosetta.
I’m not sure what you mean by that. There is an entire PostrgreSQL stack installed and building psycopg2cffi under cPython works as expected.
The issue here is that everything on M1 is supposed to be arm64 but for whatever reason under PyPy it attempts to build for x86_64 which prevents the linker from working (the warning about mixing architectures and ignoring libpq).
Is your example from an M1 machine?
Ignore my comments in this thread, I was accidentally testing it in the wrong virtualenv that was running an x86_64 build of PyPy. It installs and imports fine when using the correct architecture:
Python 3.9.12 (d4b7ddecdfcdfd39bb680b9ac3de9c658af098bb, Jul 19 2022, 01:30:22)
[PyPy 7.3.10-alpha0 with GCC Apple LLVM 13.1.6 (clang-1316.0.21.2.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
And now for something completely different: ``pypy is the nuclear fusion of
programming language implementation (pedronis)''
>>>> import platform
>>>> platform.platform()
'macOS-12.5.1-arm64-arm-64bit'
>>>> import psycopg2cffi
>>>>
I just realised that I confused something. At the moment when I used this script, there were no pypy for m1 available (they introduced it only in July 2022).
So, I ran this on m1 on rosetta, yes, and there was an issues with architecture mismatch during linking, because m1 version of postgres was installed into the system.
Now this should just work on pypy on m1, i guess.
Does anyone try to install
psycopg2cffi
on mac m1?psycopg2
works fine for me. But forpsycopg2cffi
I got this error