Python 在 CentOS 上安装 psycopg2 时遇到问题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4821094/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-18 17:40:01  来源:igfitidea点击:

Trouble installing psycopg2 on CentOS

pythonpostgresqlinstallationcentospsycopg2

提问by hdx

I'm trying to install psycopg2 on CentOS, I followed everything on this tutorialfrom "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:

我正在尝试在 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

How to troubleshoot this?

如何解决这个问题?

采纳答案by wkl

psycopg2 is a python wrapper around the PostgreSQL libraries, so you need those installed on your system too.

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

Since you're using CentOS, try this from the command line to install the postgre libs.

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

yum install postgresql-libs

yum install postgresql-libs

回答by Tometzky

  1. Forget your tutorial.
  2. Install EPEL
  3. yum install python-psycopg2
  1. 忘记你的教程。
  2. 安装 EPEL
  3. yum 安装 python-psycopg2

Django supports Python 2.4just 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.

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

回答by Coaden

I followed the first answer to install python libs:

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

yum install postgresql-lib

but it didn't work, so I also did a yum install of the devel and python:

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

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

Not sure which one did it, but my guess is the devel.

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

回答by Alvin

for ubuntu you'll want

对于 ubuntu,你会想要

sudo apt-get install python2.7-psycopg2

sudo apt-get install python2.7-psycopg2

or if using python 3

或者如果使用 python 3

sudo apt-get install python3-psycopg2

sudo apt-get install python3-psycopg2