Psycopg2无法在python 3上安装,pip发出致命错误

Psycopg2无法在python 3上安装,pip发出致命错误,pip,fedora,python-3.3,psycopg2,Pip,Fedora,Python 3.3,Psycopg2,我正在尝试在我的virtualenv中安装,以便将django与postgresql数据库连接起来 在Fedora 19和postgresql-9.2中,pg_配置的路径为: /usr/pgsql-9.2/bin 在Fedora 20中,此目录不存在 但是,可以在/usr/bin/pg\u config中找到pg\u配置 正在尝试安装psycopg2: $ yum install python3 postgresql python-devel libpqxx-devel Loaded plugi

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

在Fedora 19和postgresql-9.2中,pg_配置的路径为:

/usr/pgsql-9.2/bin

在Fedora 20中,此目录不存在

但是,可以在
/usr/bin/pg\u config
中找到pg\u配置

正在尝试安装psycopg2:

$ 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
$export PATH=$PATH:/usr/bin;pip安装psycopg2
下载/解包psycopg2
下载psycopg2-2.5.2.tar.gz(685kB):下载685kB
正在为程序包psycopg2运行setup.py egg\u info
... -正在此处编译输出-。。。
gcc-pthread-Wno unused result-DDYNAMIC\u ANNOTATIONS\u ENABLED=1-DNDEBUG-O2-g-pipe-Wall-Wp-D\u FORTIFY\u SOURCE=2-feexceptions-fstack protector-strong-param=ssp buffer size=4-grecord gcc switches-m64-mtune=generic-D\u GNU SOURCE-fPIC-fwrapv-fPIC-DPSYCOPG\u DEFAULT\u PYDATETIME=1-DPSYCOPG VERSION=“2.5.2(dt dec pq3 ext)”-DPG_VERSION_HEX=0x090302-DPSYCOPG_EXTENSIONS=1-DPSYCOPG_NEW_BOOLEAN=1-DHAVE_pqfreemm=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-wdecaration语句后
在psycopg/psycopgmodule.c中包含的文件中:27:0:
./psycopg/psycopg.h:30:20:致命错误:Python.h:没有这样的文件或目录
#包括
^
编译终止。
错误:命令“gcc”失败,退出状态为1
----------------------------------------
清理。。。
Command/home/flyer/.virtualenvs/p3test/bin/python3-c“导入setuptools;\uuuu文件\uuu='/home/flyer/.virtualenvs/p3test/build/psycopg2/setup.py';exec(编译(打开(\uu文件\uuuu).read().replace('\r\n','\n'),\uuu文件\uuu,'exec'))”安装--record/tmp/pip-mrsky4-record/install-record.txt--外部管理的单一版本--安装头/home/flyer/.virtualenvs/p3test/include/site/python3.3失败,错误代码为/home/flyer/.virtualenvs/p3test/build/psycopg2中的1
存储完整的登录/home/flyer/.pip/pip.log

非常感谢您的帮助。

您缺少python3包含文件

 $ 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
包中找到它们。

安装python3-devel包以使其正常工作

./psycopg/psycopg.h:30:20: fatal error: Python.h: No such file or directory
如果工作正常,或者需要libpq fe.h文件,请使用以下命令安装:

sudo dnf install python3-devel

如其他答案所示,这是由于没有安装正确的Python“devel”包造成的。在CentOS上,Python“devel”rpm软件包的编号为,并带有限定版本。例如,在撰写本文时,当前版本为:

python34-devel
用于epel存储库

python36u-devel
用于ius存储库

示例Yum命令(假定已配置):

sudo-yum安装python34-devel


服务器故障的相关回答:

Ubuntu上。我用以下方法解决了这个问题:

sudo dnf install postgresql-devel

您是否安装了
python3devel
?对于ubuntu,这将是
python3dev
。谢谢你的回答。这大概是一个Fedora特有的答案。它在其他发行版上工作吗?答案是针对fedora的,对于其他发行版,可能有类似的软件包可用,您可以尝试安装它们并检查它是否工作。
sudo apt-get install libpq-dev