22

我正在尝试在 CentOS 上安装 psycopg2,我按照本教程中的所有内容从“使用它:安装 Python 2.6”一直到它导入 psycopg2,但是当我尝试导入时,我收到以下错误:

 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

如何解决这个问题?

4

4 回答 4

25

psycopg2 是 PostgreSQL 库的 python 包装器,因此您也需要在系统上安装这些库。

由于您使用的是 CentOS,请尝试从命令行安装 postgre 库。

yum install postgresql-libs

于 2011-01-27T19:58:08.187 回答
23
  1. 忘记你的教程。
  2. 安装 EPEL
  3. 百胜安装 python-psycopg2

Django很好地支持 Python 2.4 。如果你真的需要 Python 2.6,你也可以使用 EPEL ( yum install python26) - 但目前还没有 psycopg2 包。

于 2011-01-27T20:04:59.290 回答
4

我按照第一个答案安装 python 库:

yum install postgresql-lib

但它没有用,所以我还对 devel 和 python 进行了 yum 安装:

yum install postgresql91-devel.x86_64
yum install postgresql91-python.x86_64

不知道是哪一个做的,但我猜是开发者。

于 2013-04-02T22:32:27.313 回答
-4

对于 ubuntu,你会想要

sudo apt-get install python2.7-psycopg2

或者如果使用 python 3

sudo apt-get install python3-psycopg2

于 2014-05-28T18:22:18.540 回答