安装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安装成功了。

猜你喜欢

转载自blog.csdn.net/tianxionj/article/details/51789234