Psycopg2: ImportError: undefined symbol: PQencryptPasswordConn

Created on 28 Nov 2019  路  6Comments  路  Source: psycopg/psycopg2

Hi everyone,

I'm running PostgreSQL 9.6.13 on a raspberry pi 3B+. I'd been running psycopg2 version 2.8.3 with python 2.7.13 fine, but (finally!) have gotten round to upgrading to python 3.7.3. I created a new venv, pip installed psycopg2, and ran into this error:

ImportError: /usr/src/prt37/lib/python3.7/site-packages/psycopg2/_psycopg.cpython-37m-arm-linux-gnueabihf.so: undefined symbol: PQencryptPasswordConn

I've check pg_config and the libpq dependencies as suggested on the FAQ, and they're both using:
/usr/lib/arm-linux-gnueabihf/libpq.so.5

Has anyone got any ideas how to solve this and what is causing it? My python 2.7 venv is still running fine.

Thanks,

Alex

Most helpful comment

Resolved by installing from source, 3.7 must've used the wheel.

git clone https://github.com/psycopg/psycopg2
cd psycopg2
`which python3.7` setup.py build
`which python3.7` setup.py install

All 6 comments

I'm pretty sure you have mismatch in the libpq header files and/or the libraries installed.

The PQencryptPasswordConn function was introduced in PG 10: psycopg uses it if it's find at compile time. However at runtime it tries to link with a pre-10 libpq and the function is not found.

Take a look at the build logs: you will likely see that PG_VERSION_NUM is greater than 10xxxx, which compiles in the PQencryptPasswordConn requirement. You can be sure of the libpq found at runtime e.g. running:

import ctypes
libpq = ctypes.cdll.LoadLibrary("libpq.so")
print(libpq.PQlibVersion())

which I bet is less that 10xxxx.

Thanks for the reply, I had a look and the result of that print statement is "90613". That all seems fine though as I want to use version 9.6 (as this is the latest supported version on the raspbian stretch OS).

Where can I find the psycopg2 build logs? There isn't anything in my "/usr/src/prt37/lib/python3.7/site-packages/psycopg2" that says what version of postgres tried to build with. postgres 9.6 is the only version on my pi, and pg_config and libpq are both looking for it.

Resolved by installing from source, 3.7 must've used the wheel.

git clone https://github.com/psycopg/psycopg2
cd psycopg2
`which python3.7` setup.py build
`which python3.7` setup.py install

@alexjpm i am still getting the same error after I did by method you mentioned. was there anything else as well I had to do after which python3.7 setup.py install

@alexjpm i am still getting the same error after I did by method you mentioned. was there anything else as well I had to do after which python3.7 setup.py install

Hi,
Are you installing directly to the system python or to a venv? If to a venv then double check the folder is owned by the right user. Other than that I didn't do anything else.

I had this same issue and solved it by:

  1. pip3 uninstall psycopg2
  2. pip3 install psycopg2-binary
  3. Uninstalling the (in my case Fedora RPM) packages for libpq and libpq-devel, which were no longer needed in my case (a lean docker container).

Things work well now.

Was this page helpful?
0 / 5 - 0 ratings