python3报:ImportError: No module named 'MySQLdb'

问题描述: 

项目在转到python3.6时,原先的导入MySQLdb模块都提示无法导入,pip install mysqldb也安装失败。
问题原因:
python2和python3在数据库模块支持这里存在区别,python2是mysqldb,而到了python3就变成mysqlclient,pip install mysqlclient即可。

pip install mysqlclient
pip3 install mysqlclient

 如果安装过程中提示 

ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

则需要先安装mysql-devel库

# Ubuntu环境
$> apt-get install libmysqlclient-dev

# centos环境
$> yum install mysql-devel gcc gcc-devel python-devel

 


参考资料:https://blog.csdn.net/zoulonglong/article/details/79539626?utm_source=copy

posted @ 2018-10-16 10:35  m0w3n  阅读(4270)  评论(0编辑  收藏  举报