python no module named mysqldb_已经装了MySQL-python,但在引用时报错:ImportError: No module named MySQLdb-阿里云开发者社...

导入MySQLdb模块的时候报错,如下

>>> import MySQLdb

Traceback (most recent call last):

File "", line 1, in

ImportError: No module named MySQLdb

在网上找了一个解决方法:

yum install MySQL-python  (centos系统)

再次导入的时候还是报错,怀疑是版本问题:

$ python --version

Python 2.7.10

$ cat /etc/issue

CentOS release 5.11 (Final)

Kernel \r on an \m

这个版本的系统默认装的是python2.4的模块:

$ rpm -ql MySQL-python

/usr/lib64/python2.4/site-packages/MySQL_python-1.2.3c1-py2.4.egg-info

/usr/lib64/python2.4/site-packages/MySQL_python-1.2.3c1-py2.4.egg-info/PKG-INFO

/usr/lib64/python2.4/site-packages/MySQL_python-1.2.3c1-py2.4.egg-info/SOURCES.txt

/usr/lib64/python2.4/site-packages/MySQL_python-1.2.3c1-py2.4.egg-info/dependency_links.txt

/usr/lib64/python2.4/site-packages/MySQL_python-1.2.3c1-py2.4.egg-info/top_level.txt

/usr/lib64/python2.4/site-packages/MySQLdb

........

........

解决方法:

2,unzip  MySQL-python-1.2.5.zip

3,安装

cd MySQL-python-1.2.5

python setup.py build

python setup.py install

再次装载模块的时候还是报错:

>>> import MySQLdb

Traceback (most recent call last):

File "", line 1, in

File "build/bdist.linux-x86_64/egg/MySQLdb/__init__.py", line 19, in

File "build/bdist.linux-x86_64/egg/_mysql.py", line 7, in

File "build/bdist.linux-x86_64/egg/_mysql.py", line 6, in __bootstrap__

ImportError: libmysqlclient.so.18: cannot open shared object file: No such file or directory

根据最后提示,应该是找不着一个交libmysqlclient.so.18的文件,于是到mysql安装目录里找到这个文件并且做一个软连接到/usr/lib

ln -sv /usr/local/ver01/percona/lib/libmysqlclient.so.18 /usr/lib64/libmysqlclient.so.18

再次装载模块的时候不再报错了。

本文转自 emma_cql 51CTO博客,原文链接:http://blog.51cto.com/chenql/1760899

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值