psycopg2
psycopg2 copied to clipboard
Linking issue with static libpq compilation
I'm currently building an app using buildozer, i've patched it to compile the version 10.12 of libpq.
Their recipe for compiling psycopg2 compiles against the static lib of libpq which works fine. Instead it breaks at runtime with the error:
ImportError: undefined symbol: PQencryptPasswordConn
I'm running with psycopg2 2.8.4 I've read the issues #1093 and #1018 but i've confirmed that the libpq version really is 10.
Hello @Progdrasil
Because the problem comes your environment I don't really have a way to know what happens there. You can see that the only use of that function is guarded at compile time.
https://github.com/psycopg/psycopg2/blob/d70d3ee482bdbeee3894656e1dcec30f38c2d999/psycopg/psycopgmodule.c#L474-L491
If you provide a docker image reproducing the issue in isolation we can try taking a look, thank you.
Funny thing is I was actually getting this issue in docker yesterday fairly systematically. But today it seems to not want to reproduce...
Thats annoying. I made a repo here which should reproduce the issue as it would happen as soon as psycopg2 was imported, but it does not. https://github.com/Progdrasil/buildozer-psycopg2-issue-1123
I have similar problem I cannot compile psycopg2 with static linking to libpq
Run inside AWS Lambda container
docker run -ti --rm --entrypoint /bin/bash --platform linux/amd64 public.ecr.aws/lambda/python:3.11
Install all needed rpm packages
yum -y install wget tar gzip gcc make flex bison perl patch
Download and compile postgresql-14.9
wget https://ftp.postgresql.org/pub/source/v14.9/postgresql-14.9.tar.gz
tar xfz postgresql-14.9.tar.gz
pushd postgresql-14.9
./configure --prefix /opt/postgresql-14.9 --without-readline --without-zlib
make
make install
popd
Download and compile psycopg2-2.9.7 with static linking to libpq
wget https://files.pythonhosted.org/packages/f7/fa/6e6bb7a7bbe4e02b35aa2fc009fb53221663a5e07e333b72cb5a85e4dbb0/psycopg2-2.9.7.tar.gz
tar xfz psycopg2-2.9.7.tar.gz
pushd psycopg2-2.9.7
sed -i 's@pg_config =.*@pg_config = /opt/postgresql-14.9/bin/pg_config@' setup.cfg
sed -i 's@static_libpq =.*@static_libpq = 1@' setup.cfg
python3 setup.py build
python3 setup.py install
popd
Import compile psycopg2 module
bash-4.2# python3 -m psycopg2
Traceback (most recent call last):
File "<frozen runpy>", line 189, in _run_module_as_main
File "<frozen runpy>", line 148, in _get_module_details
File "<frozen runpy>", line 112, in _get_module_details
File "/var/lang/lib/python3.11/site-packages/psycopg2-2.9.7-py3.11-linux-x86_64.egg/psycopg2/__init__.py", line 51, in <module>
from psycopg2._psycopg import ( # noqa
ImportError: /var/lang/lib/python3.11/site-packages/psycopg2-2.9.7-py3.11-linux-x86_64.egg/psycopg2/_psycopg.cpython-311-x86_64-linux-gnu.so: undefined symbol: scram_SaltedPassword
Any idea how can we eliminate this problem ?