我的linux服务器:2.6.18 RHEL5
gcc版本:gcc(GCC)4.1.2 20080704(Red Hat 4.1.2-51)
已安装rpm包:
python26-2.6.5-4.el5
python26-devel-2.6.5-4.el5
postgresql-devel-8.1.23-1
postgresql-libs-8.1.23-1
postgresql-devel-8.1.23-1
postgresql-8.1.23-1
当我运行“python2.6 setup.py install”时,错误信息是:
gcc -pthread -shared build/temp.linux-x86_64-2.6/psycopg/psycopgmodule.o build/temp.linux-x86_64-2.6/psycopg/green.o build/temp.linux-x86_64-2.6/psycopg/pqpath.o build/temp.linux-x86_64-2.6/psycopg/utils.o build/temp.linux-x86_64-2.6/psycopg/bytes_format.o build/temp.linux-x86_64-2.6/psycopg/connection_int.o build/temp.linux-x86_64-2.6/psycopg/connection_type.o build/temp.linux-x86_64-2.6/psycopg/cursor_int.o build/temp.linux-x86_64-2.6/psycopg/cursor_type.o build/temp.linux-x86_64-2.6/psycopg/diagnostics_type.o build/temp.linux-x86_64-2.6/psycopg/error_type.o build/temp.linux-x86_64-2.6/psycopg/lobject_int.o build/temp.linux-x86_64-2.6/psycopg/lobject_type.o build/temp.linux-x86_64-2.6/psycopg/notify_type.o build/temp.linux-x86_64-2.6/psycopg/xid_type.o build/temp.linux-x86_64-2.6/psycopg/adapter_asis.o build/temp.linux-x86_64-2.6/psycopg/adapter_binary.o build/temp.linux-x86_64-2.6/psycopg/adapter_datetime.o build/temp.linux-x86_64-2.6/psycopg/adapter_list.o build/temp.linux-x86_64-2.6/psycopg/adapter_pboolean.o build/temp.linux-x86_64-2.6/psycopg/adapter_pdecimal.o build/temp.linux-x86_64-2.6/psycopg/adapter_pint.o build/temp.linux-x86_64-2.6/psycopg/adapter_pfloat.o build/temp.linux-x86_64-2.6/psycopg/adapter_qstring.o build/temp.linux-x86_64-2.6/psycopg/microprotocols.o build/temp.linux-x86_64-2.6/psycopg/microprotocols_proto.o build/temp.linux-x86_64-2.6/psycopg/typecast.o -L. -L/usr/lib64 -lpython2.6 -lpq -o build/lib.linux-x86_64-2.6/psycopg2/_psycopg.so
/usr/bin/ld: build/temp.linux-x86_64-2.6/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 return 1
error: command 'gcc' failed with exit status 1
当我使用“gcc -fPIC”时,结果仍然相同。
答案 0 :(得分:1)
我知道这是很久以前的问题,但我最近遇到了同样的问题(虽然在CentOS系统而不是Red Hat上)。
我不确定这是否有帮助,但我的问题是libpq(与Postgres一起安装)的版本是"太旧"。对我有用的解决方案是安装2.5版本的psycopg2。这个版本足以满足我的需求。
我在这里找到了这个想法: https://github.com/psycopg/psycopg2/issues/305
我使用的是2.5版本,但也许稍微更新的版本也可以使用。我在这里找到了源代码: http://initd.org/psycopg/tarballs/PSYCOPG-2-5/