LINUX下安装MySQLdb无法import:libmysqlclient.so.16文件

今天在LINUX下安装python的MySQLdb,安装完成后,import MySQLdb时:

>>> import MySQLdb
Traceback (most recent call last):
File "", line 1, in
File "MySQLdb/__init__.py", line 19, in
import _mysql
File "build/bdist.linux-i686/egg/_mysql.py", line 7, in
File "build/bdist.linux-i686/egg/_mysql.py", line 6, in __bootstrap__
ImportError: libmysqlclient_r.so.16: cannot open shared object file: No such file or directory

检查原因,python版本为2.7.3,MySQLdb版本为1.2.3,本机默认MYSQL 为5.1.49,mysql的lib目录下有libmysqlclient_r.so.16

将mysql的lib目录下的动态链接库设置为共享,操作如下:

vim /etc/ld.so.conf

加入:libmysqlclient_r.so.16所在目录

ldconfig -v


python2.7 -c "import MySQLdb"

问题解决


你可能感兴趣的:(MySQL)