Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImportError: undefined symbol: PQencryptPasswordConn #1018

Closed
alexjpm opened this issue Nov 28, 2019 · 8 comments
Closed

ImportError: undefined symbol: PQencryptPasswordConn #1018

alexjpm opened this issue Nov 28, 2019 · 8 comments

Comments

@alexjpm
Copy link

alexjpm commented Nov 28, 2019

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

@dvarrazzo
Copy link
Member

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.

@alexjpm
Copy link
Author

alexjpm commented Nov 28, 2019

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.

@alexjpm
Copy link
Author

alexjpm commented Nov 28, 2019

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

@Harsh-Pandey
Copy link

@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
Copy link
Author

alexjpm commented Apr 6, 2020

@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.

@nmvega
Copy link

nmvega commented Oct 20, 2020

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.

@boooch
Copy link

boooch commented Mar 8, 2021

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.

Thank you, this helps me

@Anton-V-K
Copy link

The trick with uninstalling psycopg2 and installing psycopg2-binary didn't work out in my case, because the system (CentOS 7) was actually running PostgreSQL 9.5.24, while pg_config was reporting PostgreSQL 13.0 (the latter had been experimentally installed and hadn't been properly cleaned afterwards).
I couldn't find where to tune the version of PostgreSQL, so I just replaced /usr/bin/pg_config with a symlink to /usr/pgsql-9.5/bin/pg_config, and reinstaled psycopg2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants