简体   繁体   English

python-无法在centos 7上安装psycopg2

[英]python - can't install psycopg2 on centos 7

I'm trying to config Django on centos 7 According to this article Here我正在尝试根据这篇文章centos 7 上配置 Django 在这里

I installed我安装了

sudo yum install python-pip python-devel postgresql-server postgresql-devel postgresql-contrib gcc nginx 

After setup PostgreSQL for Django like creating a database, ... I try installing psycopg2 on virtualenv在像创建数据库一样为 Django 设置 PostgreSQL 之后,......我尝试在 virtualenv 上安装 psycopg2

pip install django gunicorn psycopg2

but I got this error, Anyone can help me?但是我遇到了这个错误,有人可以帮助我吗?

Collecting psycopg2
  Using cached psycopg2-2.6.2.tar.gz
Installing collected packages: psycopg2
  Running setup.py install for psycopg2 ... error
    Complete output from command /usr/bin/python3.4 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-n0buiow5/psycopg2/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-jk1w8dv1-record/install-record.txt --single-version-externally-managed --compile:
    running install
    running build
    running build_py
    creating build
    creating build/lib.linux-x86_64-3.4
    creating build/lib.linux-x86_64-3.4/psycopg2
    copying lib/tz.py -> build/lib.linux-x86_64-3.4/psycopg2
    copying lib/pool.py -> build/lib.linux-x86_64-3.4/psycopg2
    copying lib/extras.py -> build/lib.linux-x86_64-3.4/psycopg2
    copying lib/extensions.py -> build/lib.linux-x86_64-3.4/psycopg2
    copying lib/_range.py -> build/lib.linux-x86_64-3.4/psycopg2
    copying lib/__init__.py -> build/lib.linux-x86_64-3.4/psycopg2
    copying lib/psycopg1.py -> build/lib.linux-x86_64-3.4/psycopg2
    copying lib/_json.py -> build/lib.linux-x86_64-3.4/psycopg2
    copying lib/errorcodes.py -> build/lib.linux-x86_64-3.4/psycopg2
    creating build/lib.linux-x86_64-3.4/psycopg2/tests
    copying tests/test_errcodes.py -> build/lib.linux-x86_64-3.4/psycopg2/tests
    copying tests/dbapi20.py -> build/lib.linux-x86_64-3.4/psycopg2/tests
    copying tests/test_bug_gc.py -> build/lib.linux-x86_64-3.4/psycopg2/tests
    copying tests/test_async.py -> build/lib.linux-x86_64-3.4/psycopg2/tests
    copying tests/testconfig.py -> build/lib.linux-x86_64-3.4/psycopg2/tests
    copying tests/test_quote.py -> build/lib.linux-x86_64-3.4/psycopg2/tests
    copying tests/test_extras_dictcursor.py -> build/lib.linux-x86_64-3.4/psycopg2/tests
    copying tests/test_types_basic.py -> build/lib.linux-x86_64-3.4/psycopg2/tests
    copying tests/test_transaction.py -> build/lib.linux-x86_64-3.4/psycopg2/tests
    copying tests/test_cancel.py -> build/lib.linux-x86_64-3.4/psycopg2/tests
    copying tests/test_dates.py -> build/lib.linux-x86_64-3.4/psycopg2/tests
    copying tests/test_lobject.py -> build/lib.linux-x86_64-3.4/psycopg2/tests
    copying tests/dbapi20_tpc.py -> build/lib.linux-x86_64-3.4/psycopg2/tests
    copying tests/test_copy.py -> build/lib.linux-x86_64-3.4/psycopg2/tests
    copying tests/test_types_extras.py -> build/lib.linux-x86_64-3.4/psycopg2/tests
    copying tests/test_psycopg2_dbapi20.py -> build/lib.linux-x86_64-3.4/psycopg2/tests
    copying tests/test_module.py -> build/lib.linux-x86_64-3.4/psycopg2/tests
    copying tests/__init__.py -> build/lib.linux-x86_64-3.4/psycopg2/tests
    copying tests/test_green.py -> build/lib.linux-x86_64-3.4/psycopg2/tests
    copying tests/testutils.py -> build/lib.linux-x86_64-3.4/psycopg2/tests
    copying tests/test_with.py -> build/lib.linux-x86_64-3.4/psycopg2/tests
    copying tests/test_cursor.py -> build/lib.linux-x86_64-3.4/psycopg2/tests
    copying tests/test_connection.py -> build/lib.linux-x86_64-3.4/psycopg2/tests
    copying tests/test_notify.py -> build/lib.linux-x86_64-3.4/psycopg2/tests
    copying tests/test_bugX000.py -> build/lib.linux-x86_64-3.4/psycopg2/tests
    Skipping optional fixer: buffer
    Skipping optional fixer: idioms
    Skipping optional fixer: set_literal
    Skipping optional fixer: ws_comma
    running build_ext
    building 'psycopg2._psycopg' extension
    creating build/temp.linux-x86_64-3.4
    creating build/temp.linux-x86_64-3.4/psycopg
    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.6.2 (dt dec pq3 ext)" -DPG_VERSION_HEX=0x090212 -I/usr/include/python3.4m -I. -I/usr/include -I/usr/include/pgsql/server -c psycopg/psycopgmodule.c -o build/temp.linux-x86_64-3.4/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

    ----------------------------------------
Command "/usr/bin/python3.4 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-n0buiow5/psycopg2/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-jk1w8dv1-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-n0buiow5/psycopg2/

Tested with Python 3:用 Python 3 测试:

sudo yum groupinstall "Development Tools"
sudo yum install python3-devel
sudo yum install postgresql-libs
sudo yum install postgresql-devel
[sudo] pip install psycopg2

你似乎缺少一个

sudo yum install postgresql-libs

http://mirror.centos.org/centos/7/os/x86_64/Packages/ http://mirror.centos.org/centos/7/os/x86_64/Packages/

Test this测试这个

yum install python-psycopg2 yum 安装 python-psycopg2

The installation of postgresql-libs does not help, it actually needs a valid postgresql client. postgresql-libs的安装没有帮助,它实际上需要一个有效的 postgresql 客户端。 Therefore installing the devel package for CentOS 7 solves it (if it's not an overkill for you).因此,为 CentOS 7 安装 devel 包可以解决它(如果它对您来说不是矫枉过正的话)。

yum install postgresql-devel

This started happening due to the fact that the pip package stopped shipping with postgresql client binaries, which makes sense since you might want to use a different version in certain scenarios.这开始发生是因为 pip 包停止与 postgresql 客户端二进制文件一起发送,这是有道理的,因为您可能希望在某些情况下使用不同的版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM