/usr/bin/ld: cannot find -lpython2.7

2019-02-02 11:04发布

I'm trying to install MySQLdb with Python 2.7. The error I'm getting looks like this:

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*
python2@
python2.4*
python2.7@

What does the @ symbol mean? Can anyone advise a remedy to the error?

2条回答
混吃等死
2楼-- · 2019-02-02 11:13

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).

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).

查看更多
Animai°情兽
3楼-- · 2019-02-02 11:13

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:

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.

查看更多
登录 后发表回答