简体   繁体   English

psycopg2无法在centOS上安装

[英]psycopg2 fails to install on centOS

I am trying to install psycopg2 on centOS. 我正在尝试在centOS上安装psycopg2。

I did 我做了

yum install postgresql-libs python-devel
yum install postgresql-devel
yum install postgresql postgresql-contrib

When I do 当我做

pip install psycopg2

I get 我懂了

gcc -pthread -shared build/temp.linux-x86_64-2.7/psycopg/psycopgmodule.o 
build/temp.linux-x86_64-2.7/psycopg/green.o 
build/temp.linux-x86_64-2.7/psycopg/pqpath.o 
build/temp.linux-x86_64-2.7/psycopg/utils.o 
build/temp.linux-x86_64-2.7/psycopg/bytes_format.o 
build/temp.linux-x86_64-2.7/psycopg/connection_int.o 
build/temp.linux-x86_64-2.7/psycopg/connection_type.o 
build/temp.linux-x86_64-2.7/psycopg/cursor_int.o 
build/temp.linux-x86_64-2.7/psycopg/cursor_type.o 
build/temp.linux-x86_64-2.7/psycopg/diagnostics_type.o 
build/temp.linux-x86_64-2.7/psycopg/error_type.o 
build/temp.linux-x86_64-2.7/psycopg/lobject_int.o 
build/temp.linux-x86_64-2.7/psycopg/lobject_type.o 
build/temp.linux-x86_64-2.7/psycopg/notify_type.o 
build/temp.linux-x86_64-2.7/psycopg/xid_type.o 
build/temp.linux-x86_64-2.7/psycopg/adapter_asis.o 
build/temp.linux-x86_64-2.7/psycopg/adapter_binary.o 
build/temp.linux-x86_64-2.7/psycopg/adapter_datetime.o 
build/temp.linux-x86_64-2.7/psycopg/adapter_list.o 
build/temp.linux-x86_64-2.7/psycopg/adapter_pboolean.o 
build/temp.linux-x86_64-2.7/psycopg/adapter_pdecimal.o 
build/temp.linux-x86_64-2.7/psycopg/adapter_pint.o
build/temp.linux-x86_64-2.7/psycopg/adapter_pfloat.o 
build/temp.linux-x86_64-2.7/psycopg/adapter_qstring.o 
build/temp.linux-x86_64-2.7/psycopg/microprotocols.o 
build/temp.linux-x86_64-2.7/psycopg/microprotocols_proto.o
build/temp.linux-x86_64-2.7/psycopg/typecast.o -L/usr/lib64 -lpq -o
build/lib.linux-x86_64-2.7/psycopg2/_psycopg.so
/usr/bin/ld: build/temp.linux-x86_64-2.7/psycopg/psycopgmodule.o: 
relocation R_X86_64_PC32 against `lobjectType' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: Bad value
collect2: ld returned 1 exit status
error: command 'gcc' failed with exit status 1

----------------------------------------
Failed building wheel for psycopg2
Failed to build psycopg2

Even if I download psycopg2 from http://initd.org/psycopg/tarballs/PSYCOPG-2-6/psycopg2-2.6.tar.gz and do python setup.py install , I get the same error. 即使我从http://initd.org/psycopg/tarballs/PSYCOPG-2-6/psycopg2-2.6.tar.gz下载了psycopg2并执行python setup.py install ,我也会遇到相同的错误。

what's wrong? 怎么了?

Install additional libs : 安装其他libs

sudo yum install python-devel postgresql-devel postgresql-libs gcc

and in virtualenv export path to postgres: 并在virtualenv导出到postgres的路径中:

export PATH=/path/to/compiled/postgresql/bin:"$PATH"

in most cases it is (note you have to set correct version in path, eg for PostgreSQL 9.5 it will be psql-9.5 and so on): 在大多数情况下是这样(请注意,您必须在路径中设置正确的版本,例如对于PostgreSQL 9.5,它将是psql-9.5,依此类推):

export PATH=/usr/pgsql-9.4/bin:"$PATH"

版本2.3.1中已解决的问题安装版本2.3.1: https : //pypi.python.org/pypi/psycopg2/2.3.1

Check this issue on github even answer is there. 在github上检查这个问题,甚至答案在那里。

https://github.com/psycopg/psycopg2/issues/305 https://github.com/psycopg/psycopg2/issues/305

You need to install the correct version of python-devel. 您需要安装正确版本的python-devel。 If you are using python3 then you will need the right version of python3 devel. 如果您使用的是python3,则需要正确版本的python3 devel。

First make sure you have postgresql-devel installed: 首先确保您已安装postgresql-devel:

yum install postgresql-devel

To make sure you have the correct version do a search like following: 为了确保您具有正确的版本,请执行以下搜索:

yum search devel | grep python

Choose the write python version devel package and install it. 选择写入python版本的devel软件包并安装它。 For python3 it was 对于python3

yum install python3-devel.x86_64

Finally you can install psycopg2 using pip: 最后,您可以使用pip安装psycopg2:

pip install psycopg2

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

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