解决importerror no module named mysqldb
系统:ubuntu
语言:Python
使用MySQLdb ,但是提示importerror no module named mysqldb
Python中最连接Mysql常用的驱动是:
mysql-python :mysql的C语言的驱动
mysql-connector:msql官方的驱动
pymysql:python语言的驱动
我这里安装的是 mysql-python
终端中执行:
pip install mysql-python
但是执行完,终端打印
Collecting mysql-python
Downloading MySQL-python-1.2.5.zip (108kB)
100% |████████████████████████████████| 110kB 30kB/s
Complete output from command python setup.py egg_info:
sh: mysql_config: command not found
Traceback (most recent call last):
File "<string>", line 20, in <module>
File "/private/tmp/pip-build-NP8J3v/mysql-python/ setup.py", line 17, in <module>
metadata, options = get_config()
File "setup_posix.py", line 43, in get_config
libs = mysql_config("libs_r")
File "setup_posix.py", line 25, in mysql_config
raise EnvironmentError("%s not found" % (mysql_config.path,))
EnvironmentError: mysql_config not found
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/tmp/pip-build-NP8J3v/mysql-python
如果忽略这个错误,那么在执行程序的时候回报错:importerror no module named mysqldb
用以下方式解决:
sudo apt-get install python-mysqldb
pip install mysql-python
这样就可以了。