/ usr / bin / ld:找不到-lpython2.7

时间:2011-12-06 12:58:30

标签: python linux mysql-python

我正在尝试使用Python 2.7安装MySQLdb。我得到的错误看起来像这样:

gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -Dversion_info=(1,2,3,'final',0) -D__version__=1.2.3 -I/usr/include/mysql -I/opt/python2.7/include/python2.7 -c _mysql.c -o build/temp.linux-x86_64-2.7/_mysql.o -g -pipe -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64
gcc -pthread -shared build/temp.linux-x86_64-2.7/_mysql.o -L/usr/lib64/mysql -L. -lmysqlclient_r -lz -lpthread -lcrypt -lnsl -lm -lpthread -lmygcc -lpython2.7 -o build/lib.linux-x86_64-2.7/_mysql.so
/usr/bin/ld: cannot find -lpython2.7
collect2: ld returned 1 exit status
error: command 'gcc' failed with exit status 1

显然,它找不到Python 2.7。查看/usr/bin我看到了:

python*
python2@
python2.4*
python2.7@

@符号是什么意思?任何人都可以建议补救错误吗?

2 个答案:

答案 0 :(得分:18)

找不到Python库,而不是可执行文件。运行locate libpython2.7.a以查看Python库的位置,并将其添加到库路径中(例如,如果它位于/opt/python2.7/lib中,则要调用LDFLAGS="-L/opt/python2.7/lib" make)。

@符号表示文件是符号链接; *表示它是可执行文件(由ls -F生成,您可能将其作为别名)。

答案 1 :(得分:9)

上面的解决方案对我来说并不是很好,因为我使用pip来安装mysql-python,但绝对是朝着正确方向发展的重要推动力。为了让Google在与我相同的情况下来到这里的任何人的利益,我的解决方案是将python安装目录中的libpython2.7.a符号链接到lib目录:

  

ln -s /opt/python2.7.1/lib/python2.7/config/libpython2.7.a   的/ usr /本地/ LIB /

pip install mysql-python之后没有任何问题。