I'm trying to install psycopg2 on CentOS, I followed everything on this tutorial from "On with it: Installing Python 2.6" all the way to when it imports psycopg2, but when I try to import I get the following error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/opt/python2.6/lib/python2.6/site-packages/psycopg2/__init__.py", line 69, in <module>
from _psycopg import BINARY, NUMBER, STRING, DATETIME, ROWID
ImportError: libpq.so.5: cannot open shared object file: No such file or directory
How to troubleshoot this?
The current psycopg2 implementation supports: Python 2 versions from 2.6 to 2.7. Python 3 versions from 3.2 to 3.6. PostgreSQL server versions from 7.4 to 9.6.
psycopg2-binary and psycopg2 both give us the same code that we interact with. The difference between the two is in how that code is installed in our computer.
Psycopg2 is a DB API 2.0 compliant PostgreSQL driver that is actively developed. It is designed for multi-threaded applications and manages its own connection pool.
psycopg2 is a python wrapper around the PostgreSQL libraries, so you need those installed on your system too.
Since you're using CentOS, try this from the command line to install the postgre libs.
yum install postgresql-libs
Django supports Python 2.4 just fine. If you really need Python 2.6 you can also use EPEL (yum install python26
) - but there's no psycopg2 package for it yet.
I followed the first answer to install python libs:
yum install postgresql-lib
but it didn't work, so I also did a yum install of the devel and python:
yum install postgresql91-devel.x86_64
yum install postgresql91-python.x86_64
Not sure which one did it, but my guess is the devel.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With