问题:
运行程序提示:ImportError: No module named MySQLdb
解决步骤:
1、安装MySQL-python包,提示错误:EnvironmentError: mysql_config not found
[root@VM static]# pip2 install MySQL-pythonLooking in indexes: /pypi/simpleCollecting MySQL-pythonDownloading /pypi/packages/a5/e9/51b544da85a36a68debe7a7091f068d802fc515a3a202652828c73453cad/MySQL-python-1.2.5.zip (108kB)100% |████████████████████████████████| 112kB 822kB/s Complete output from command python setup.py egg_info:sh: mysql_config: 未找到命令Traceback (most recent call last):File "<string>", line 1, in <module>File "/tmp/pip-install-p9LTrB/MySQL-python/setup.py", line 17, in <module>metadata, options = get_config()File "setup_posix.py", line 43, in get_configlibs = mysql_config("libs_r")File "setup_posix.py", line 25, in mysql_configraise EnvironmentError("%s not found" % (mysql_config.path,))EnvironmentError: mysql_config not found
2、MySQL-python包依赖mysql-devel包,需首先安装mysql-devel包
yum -y install mysql-devel
3、安装完成mysql-devel包,再次安装MySQL-python包成功
[root@VM static]# pip2 install MySQL-pythonLooking in indexes: /pypi/simpleCollecting MySQL-pythonDownloading /pypi/packages/a5/e9/51b544da85a36a68debe7a7091f068d802fc515a3a202652828c73453cad/MySQL-python-1.2.5.zip (108kB)100% |████████████████████████████████| 112kB 890kB/s Installing collected packages: MySQL-pythonRunning setup.py install for MySQL-python ... doneSuccessfully installed MySQL-python-1.2.5