安装MySQLdb模块遭遇”fatal error: my_config.h: No such file or directory”的处理

  • Post author:
  • Post category:mysql




Issue






I encountered an error when I run the python script which need to import the module of “MySQLdb”.The error shows like this:



[root@docker1 script]#

python Xtrabackup.py


Traceback (most recent call last):

File “backup.py”, line 11, in <module>

import MySQLdb

ImportError: No module named MySQLdb




Then I downloaded and installed the latest version of pip to install MySQLdb module:




[root@docker1 pip-18.0]#

python setup.py install




[root@docker1 pip-18.0]# pip –version

pip 18.0 from /usr/lib/python2.7/site-packages/pip-18.0-py2.7.egg/pip (python 2.7)




But it still doesn’t work.it showed “fatal error: my_config.h: No such file or directory”:




[root@docker1 script]#

easy_install pip


Searching for pip

Best match: pip 18.0

Processing pip-18.0-py2.7.egg

pip 18.0 is already the active version in easy-install.pth

Installing pip script to /usr/bin

Installing pip2.7 script to /usr/bin

Installing pip2 script to /usr/bin


Using /usr/lib/python2.7/site-packages/pip-18.0-py2.7.egg

Processing dependencies for pip

Finished processing dependencies for pip

[root@docker1 script]#

pip install mysql-python


Collecting mysql-python

Using cached https://files.pythonhosted.org/packages/a5/e9/51b544da85a36a68debe7a7091f068d802fc515a3a202652828c73453cad/MySQL-python-1.2.5.zip

Installing collected packages: mysql-pyt