python安装是 -fPIC问题的解决

尼玛真是头疼。


在安装好numpy、scipy、theano后。
在python代码中,敲入:import theano,报错如下:


Problem occurred during compilation with the command line below:

g++ -shared -g -m64 -fPIC -I/usr/local/lib/python2.7/site-packages/numpy/cor
e/include -I/usr/local/include/python2.7 -o /root/.theano/compiledir_Linux-2
.6.18-308.el5-x86_64-with-redhat-5.8-Tikanga-x86_64-2.7.3-64/lazylinker_ext/
lazylinker_ext.so /root/.theano/compiledir_Linux-2.6.18-308.el5-x86_64-with-
redhat-5.8-Tikanga-x86_64-2.7.3-64/lazylinker_ext/mod.cpp -L/usr/local/lib -
lpython2.7

/usr/bin/ld: /usr/local/lib/libpython2.7.a(abstract.o): relocation R_X86_64_
32 against `a local symbol' can not be used when making a shared object; rec
ompile with -fPIC

/usr/local/lib/libpython2.7.a: could not read symbols: Bad value

collect2: ld returned 1 exit status

Traceback (most recent call last):

File "<stdin>", line 1, in <module>

File "theano/__init__.py", line 55, in <module>

from theano.compile import \

File "theano/compile/__init__.py", line 5, in <module>

from theano.compile.function_module import *

File "theano/compile/function_module.py", line 18, in <module>

import theano.compile.mode

File "theano/compile/mode.py", line 11, in <module>

import theano.gof.vm

File "theano/gof/vm.py", line 486, in <module>

import lazylinker_c

File "theano/gof/lazylinker_c.py", line 89, in <module>

preargs=args)

File "theano/gof/cmodule.py", line 1829, in compile_str

(status, compile_stderr.replace(b('\n'), b('. '))))

Exception: Compilation failed (return status=1): /usr/bin/ld: /usr/local/lib
/libpython2.7.a(abstract.o): relocation R_X86_64_32 against `a local symbol'
can not be used when making a shared object; recompile with -fPIC. /usr/loc
al/lib/libpython2.7.a: could not read symbols: Bad value. collect2: ld retur
ned 1 exit status.


仔细分析错误代码之后,定位原因在于,
python在编译时,libpython2.7.a库中的abstract.o模块的编译过程中,没有加上-fPIC;

按照网上的方法,各种在python编译过程中加上-fPIC参数,都没有解决;
最后仔细看make命令的输出结果,发现abstract.o模块根本就没有经过编译。
继续最终,发现Python的源码路径中Object下,abstract.c和abstract.o都存在,而且这个文件是下载python包是就已经编译好了的(生成了.o文件);
然后删除所有.o文件,然后重新make,在make,就有abstract.o的编译过程了。

尼玛,这个问题整整搞了我10个小时,不知道能不能完全解决。

------------

尼玛,就知道没有那么容易,后来又报另外一个包需要重新编译。
然后我把Python源码目录中所有自带的.o文件删了,然后就ok啦。。。


安装命令如下:


./configure --prefix=/usr/local/ –enable-shared CFLAGS=-fPIC
make
make install
  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值