---
title: "python安装是 -fPIC问题的解决"
author: "Taoo"
date: "2013-03-09T21:52:24Z"
tags: []
categories: ["编程语言"]
slug: "python-fpic"
draft: false
lastmod: "2013-03-09T21:52:24Z"
id: 1826912
url: "https://taoo.iteye.com/blog/1826912"
---

尼玛真是头疼。


在安装好numpy、scipy、theano后。
在python代码中，敲入：import theano，报错如下：


```error

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啦。。。



安装命令如下：


```shell

./configure --prefix=/usr/local/  –enable-shared CFLAGS=-fPIC
make
make install

```