Linux /usr/bin/ld: 找不到 -lpython2.7
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8400272/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
/usr/bin/ld: cannot find -lpython2.7
提问by Mike
I'm trying to install MySQLdb with Python 2.7. The error I'm getting looks like this:
我正在尝试使用 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
Clearly, it can't find Python 2.7. Looking in /usr/bin
I see:
显然,它找不到 Python 2.7。看着/usr/bin
我看到:
python*
python2@
python2.4*
python2.7@
What does the @
symbol mean? Can anyone advise a remedy to the error?
什么是@
符号是什么意思?任何人都可以建议纠正错误吗?
采纳答案by Petr Viktorin
It can't find the Python library, not the executable. Run locate libpython2.7.a
to see where your Python library is located, and add it to the library path (e.g. if it is in /opt/python2.7/lib
, you want to call LDFLAGS="-L/opt/python2.7/lib" make
).
它找不到 Python 库,而不是可执行文件。运行locate libpython2.7.a
以查看您的 Python 库所在的位置,并将其添加到库路径中(例如,如果它在 中/opt/python2.7/lib
,您想调用LDFLAGS="-L/opt/python2.7/lib" make
)。
The @
symbol means the file is a symbolic link; *
means it's executable (these are produced by ls -F
, which you might have as an alias).
该@
符号意味着该文件是一个符号链接; *
意味着它是可执行的(这些是由 生成的ls -F
,您可能将其作为别名)。
回答by Aaron
The above solution didn't quite do it for me as I was using pip to install mysql-python, but was definitely a big push in the right direction. For the benefit of anyone who lands here from Google in the same situation as me, my solution was to symlink libpython2.7.a from the python installation directory to the lib dir:
当我使用 pip 安装 mysql-python 时,上述解决方案对我来说并没有完全成功,但绝对是朝着正确方向迈出的一大步。为了在与我相同的情况下从 Google 登陆这里的任何人的利益,我的解决方案是将 libpython2.7.a 从 python 安装目录符号链接到 lib 目录:
ln -s /opt/python2.7.1/lib/python2.7/config/libpython2.7.a /usr/local/lib/
ln -s /opt/python2.7.1/lib/python2.7/config/libpython2.7.a /usr/local/lib/
pip install mysql-python worked without any issues afterwards.
pip install mysql-python 之后没有任何问题。