OS: CentOS 6.6
Python: 2.6.6
Pip: 7.1.0 (Pip安装请参考https://pip.pypa.io/en/stable/installing.html)
pip install MySQL-python --user
一条命令即可解决,--user
选项是为当前用户,也是普通用户安装MySQLdb.
缺少python-dev的包:
错误表现为,
pymemcompat.h:10:20: error: Python.h: No such file or directory
解决方法为,
yum install python-devel
缺少MySQL的开发包:
错误表现为,
_mysql.c:36:23: error: my_config.h: No such file or directory
_mysql.c:38:19: error: mysql.h: No such file or directory
_mysql.c:39:26: error: mysqld_error.h: No such file or directory
_mysql.c:40:20: error: errmsg.h: No such file or directory
解决方法为,
yum install mysql-devel
输入命令:
python -c 'import MySQLdb'
如果没有任何输出,表示MySQLdb已安装完成.
参考
安装MySQL易错点