Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trouble installing psycopg2 on CentOS

Tags:

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?

like image 954
hdx Avatar asked Jan 27 '11 19:01

hdx


People also ask

Does psycopg2 work with Python 3?

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.

Is psycopg2 the same as psycopg2-binary?

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.

Is psycopg2 a database driver?

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.


3 Answers

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

like image 200
逆さま Avatar answered Sep 24 '22 15:09

逆さま


  1. Forget your tutorial.
  2. Install EPEL
  3. yum install python-psycopg2

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.

like image 29
Tometzky Avatar answered Sep 24 '22 15:09

Tometzky


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.

like image 24
Coaden Avatar answered Sep 26 '22 15:09

Coaden