Trouble installing psycopg2 on CentOS
Asked Answered
S

5

23

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?

Shaper answered 27/1, 2011 at 19:49 Comment(1)
This will give the current version installed: python -c "import psycopg2; print(psycopg2.__version__)"Alternation
S
25

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

Straightlaced answered 27/1, 2011 at 19:58 Comment(5)
looks like AWS saying "yum doesn't have postgresql-libs" or "-lib"Actuary
CentOS 6.2 says: "No package postgresql-libs available"Cervantez
Does this require sudo access or not ?Franciscafranciscan
@Franciscafranciscan Most likely, yes.Straightlaced
In CentOs 8.0 you must install another package: dnf install postgresql-develHomochromous
F
23
  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.

Flatcar answered 27/1, 2011 at 20:4 Comment(2)
on amz linux at the time of writing this, step 3 is sufficientJessejessee
after days of fighting, this was the answer. Thank you!Iolenta
S
4

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.

Selfesteem answered 2/4, 2013 at 22:32 Comment(5)
Why the negative comments? INdeed "postgresql-devel" is required!Spartan
@Selfesteem you should use "postgresql-libs" with a "s" at the endYttria
yum install postgresql-devel is what I had to do as well on centos 7Heathenish
postgresql-libs isn't sufficient. I just tried it. After installing postgresql-devel it worked.Paries
For me this is worked: sudo yum install postgresql-devel followed by sudo pip install psycopg2Luo
L
0

I had the same issue that python-psycopg2 disappeared after a PostgreSQL uninstallation and yum install python-psycopg2 no longer found the package. Here is how I got it installed again.

First, install the pgdg-redhat yum repository:

yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-6-x86_64/pgdg-redhat-repo-latest.noarch.rpm

This will create the file /etc/yum.repos.d/pgdg-redhat-all.repo which lists many repositories (of which most seem to be broken). The only source of python-psycopg2 seems to be the pgdg11 repo:

[pgdg11]
name=PostgreSQL 11 for RHEL/CentOS $releasever - $basearch
enabled=0
baseurl=https://download.postgresql.org/pub/repos/yum/11/redhat/rhel-$releasever-$basearch
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-PGDG

Now you can install the package by explicitly enabling the repository containing the package:

yum install python-psycopg2 --enablerepo=pgdg11
Lifeline answered 24/8, 2023 at 10:16 Comment(0)
S
-4

for ubuntu you'll want

sudo apt-get install python2.7-psycopg2

or if using python 3

sudo apt-get install python3-psycopg2

Syllogism answered 28/5, 2014 at 18:22 Comment(4)
not sure why this got a few down-votes -- was up-voted previously for being useful to other ubuntu usersSyllogism
likely because plpython is not psycopg2, they are very different thingsArmenian
also: question is about CentOS, not about Ubuntu.Cuirass
currently at -4 -- originally found this through google searching about ubuntu so figured I'd help the next guy -- 1 more comment asking to remove and it's gone... or ask to keep itSyllogism

© 2022 - 2024 — McMap. All rights reserved.