安裝MySQLdb for centos 7--小白教程
1.MySQLdb下載地址:
https://pypi.python.org/pypi/MySQL-python/1.2.5
2. unzip MySQL-python-1.2.5;
3. cd MySQL-python-1.2.5;
python setup.py install;
此時報錯:
Traceback (most recent call last):
File "setup.py", line 17, in <module>
metadata, options = get_config()
File "/root/MySQL-python-1.2.5/setup_posix.py", line 43, in get_config
libs = mysql_config("libs_r")
File "/root/MySQL-python-1.2.5/setup_posix.py", line 25, in mysql_config
raise EnvironmentError("%s not found" % (mysql_config.path,))
EnvironmentError: mysql_config not found
原因是沒有安裝mysql-devel;
yum install mysql-devel;
4.重新執行python setup.py install;
此時報錯:
unable to execute gcc: No such file or directory
error: command 'gcc' failed with exit status 1
安裝gcc就可以了: yum install gcc;
5.再次執行python setup.py install;
fatal error: Python.h: No such file or directory
#include "Python.h"
^
compilation terminated.
error: command 'gcc' failed with exit status 1
安裝:yum install python-devel;
注意:有很多資料說要下載python-dev,說的是centos6,
centos7上是下載不來的;
6.執行 python setup.py install;
Processing dependencies for MySQL-python==1.2.5
Finished processing dependencies for MySQL-python==1.2.5
至此MySQLdb安裝成功了。