【问题标题】:Psycopg2 fails to install on python 3 with pip issuing a fatal errorPsycopg2 无法在 python 3 上安装,pip 发出致命错误
【发布时间】:2014-02-08 19:08:37
【问题描述】:
$ yum install python3 postgresql python-devel libpqxx-devel
Loaded plugins: langpacks, refresh-packagekit
Package python3-3.3.2-8.fc20.x86_64 already installed and latest version
Package postgresql-9.3.2-2.fc20.x86_64 already installed and latest version
Package python-devel-2.7.5-9.fc20.x86_64 already installed and latest version
Package 1:libpqxx-devel-3.2-0.5.fc20.x86_64 already installed and latest version
Nothing to do

我正在尝试在我的 virtualenv 中安装 psycopg2 以将 django 与 postgresql 数据库连接起来。

在 Fedora 19 和 postgresql-9.2 中,pg_config 的路径是:

/usr/pgsql-9.2/bin

在 Fedora 20 中,此目录不存在。

但是 pg_config 可以在 /usr/bin/pg_config 中找到。

尝试安装 psycopg2:

 $ export PATH=$PATH:/usr/bin; pip install psycopg2
Downloading/unpacking psycopg2
  Downloading psycopg2-2.5.2.tar.gz (685kB): 685kB downloaded
  Running setup.py egg_info for package psycopg2

... -compiling output here- ...

gcc -pthread -Wno-unused-result -DDYNAMIC_ANNOTATIONS_ENABLED=1 -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -DPSYCOPG_DEFAULT_PYDATETIME=1 -DPSYCOPG_VERSION="2.5.2 (dt dec pq3 ext)" -DPG_VERSION_HEX=0x090302 -DPSYCOPG_EXTENSIONS=1 -DPSYCOPG_NEW_BOOLEAN=1 -DHAVE_PQFREEMEM=1 -I/usr/include/python3.3m -I. -I/usr/include -I/usr/include/pgsql/server -c psycopg/psycopgmodule.c -o build/temp.linux-x86_64-3.3/psycopg/psycopgmodule.o -Wdeclaration-after-statement

In file included from psycopg/psycopgmodule.c:27:0:

./psycopg/psycopg.h:30:20: fatal error: Python.h: No such file or directory

 #include <Python.h>

                    ^

compilation terminated.

error: command 'gcc' failed with exit status 1

----------------------------------------
Cleaning up...
Command /home/flyer/.virtualenvs/p3test/bin/python3 -c "import setuptools;__file__='/home/flyer/.virtualenvs/p3test/build/psycopg2/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-mrsky4-record/install-record.txt --single-version-externally-managed --install-headers /home/flyer/.virtualenvs/p3test/include/site/python3.3 failed with error code 1 in /home/flyer/.virtualenvs/p3test/build/psycopg2
Storing complete log in /home/flyer/.pip/pip.log

感谢您的帮助。

【问题讨论】:

  • 您是否安装了python3-devel

标签: pip fedora python-3.3 psycopg2


【解决方案1】:

您缺少 python3 包含文件

./psycopg/psycopg.h:30:20: fatal error: Python.h: No such file or directory

您可能可以在 python3-devel 包中找到它们。

【讨论】:

  • 对于 ubuntu 这将是 python3-dev 。感谢您的回答。
【解决方案2】:

安装 python3-devel 包以使其工作

sudo dnf install python3-devel

如果它可以正常工作,或者如果它需要 libpq-fe.h 文件,则使用以下命令安装它:

sudo dnf install postgresql-devel

【讨论】:

  • 这大概是 Fedora 特定的答案。它适用于其他发行版吗?
  • 答案是fedora特有的,对于其他发行版,可能有类似的软件包可用,您可以尝试安装它们并检查它是否有效。
【解决方案3】:

Ubuntu 上。我解决了这个问题:

sudo apt-get install libpq-dev

【讨论】:

    【解决方案4】:

    如其他答案所示,这是由于未安装正确的 Python“开发”包造成的。在 CentOS 上,Python “devel” rpm 包的编号是带有合格版本的 。例如,在撰写本文时,当前版本是:

    python34-devel 用于 epel 存储库

    python36u-devel 用于 ius 存储库

    示例 Yum 命令(假设已配置 EPEL repository):

    sudo yum install python34-devel

    服务器故障相关回答:https://serverfault.com/questions/710354/repository-for-python3-devel-on-centos-7

    【讨论】:

      猜你喜欢
      • 2012-07-17
      • 1970-01-01
      • 2015-09-18
      • 2018-09-23
      • 2020-07-05
      • 2019-10-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多