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-python
  Running setup.py install for mysql-python ... error
    Complete output from command /usr/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-pm5hyO/mysql-python/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-record-GBdMPj/install-record.txt --single-version-externally-managed --compile:
    running install
    running build
    running build_py
    creating build
    creating build/lib.linux-x86_64-2.7
    copying _mysql_exceptions.py -> build/lib.linux-x86_64-2.7
    creating build/lib.linux-x86_64-2.7/MySQLdb
    copying MySQLdb/__init__.py -> build/lib.linux-x86_64-2.7/MySQLdb
    copying MySQLdb/converters.py -> build/lib.linux-x86_64-2.7/MySQLdb
    copying MySQLdb/connections.py -> build/lib.linux-x86_64-2.7/MySQLdb
    copying MySQLdb/cursors.py -> build/lib.linux-x86_64-2.7/MySQLdb
    copying MySQLdb/release.py -> build/lib.linux-x86_64-2.7/MySQLdb
    copying MySQLdb/times.py -> build/lib.linux-x86_64-2.7/MySQLdb
    creating build/lib.linux-x86_64-2.7/MySQLdb/constants
    copying MySQLdb/constants/__init__.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants
    copying MySQLdb/constants/CR.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants
    copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants
    copying MySQLdb/constants/ER.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants
    copying MySQLdb/constants/FLAG.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants
    copying MySQLdb/constants/REFRESH.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants
    copying MySQLdb/constants/CLIENT.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants
    running build_ext
    building '_mysql' extension
    creating build/temp.linux-x86_64-2.7
    gcc -pthread -fno-strict-aliasing -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -Dversion_info=(1,2,5,'final',1) -D__version__=1.2.5 -I/usr/local/mysql/include -I/usr/include/python2.7 -c _mysql.c -o build/temp.linux-x86_64-2.7/_mysql.o
    _mysql.c:44:23: fatal error: my_config.h: No such file or directory
     #include "my_config.h"
                           ^
    compilation terminated.
    error: command 'gcc' failed with exit status 1
    
    ----------------------------------------
Command "/usr/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-pm5hyO/mysql-python/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-record-GBdMPj/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-install-pm5hyO/mysql-python/
[root@docker1 script]# 
 
    I even download the MySQL-python package without pip tool to install MySQLdb module,but it turned out to be the same error like using pip.
 
[root@docker1script]# cd MySQL-python-1.2.5
[root@docker1 MySQL-python-1.2.5]# ll
total 171
drwxrwxrwx 1 mysql mysql 4096 Sep 18 10:17 doc
-rwxrwxrwx 1 mysql mysql 18092 Oct 8 2012 GPL-2.0
-rwxrwxrwx 1 mysql mysql 5687 Jan 1 2013 HISTORY
-rwxrwxrwx 1 mysql mysql 6636 Oct 8 2012 INSTALL
-rwxrwxrwx 1 mysql mysql 309 Jan 2 2014 MANIFEST.in
-rwxrwxrwx 1 mysql mysql 2039 Jan 2 2014 metadata.cfg
-rwxrwxrwx 1 mysql mysql 84709 Jan 2 2014 _mysql.c
drwxrwxrwx 1 mysql mysql 4096 Sep 18 10:17 MySQLdb
-rwxrwxrwx 1 mysql mysql 2352 Oct 8 2012 _mysql_exceptions.py
drwxrwxrwx 1 mysql mysql 4096 Sep 18 10:17 MySQL_python.egg-info
-rwxrwxrwx 1 mysql mysql 1689 Jan 2 2014 PKG-INFO
-rwxrwxrwx 1 mysql mysql 3203 Oct 8 2012 pymemcompat.h
-rwxrwxrwx 1 mysql mysql 1266 Oct 4 2012 README.md
-rwxrwxrwx 1 mysql mysql 398 Jan 2 2014 setup.cfg
-rwxrwxrwx 1 mysql mysql 1088 Oct 8 2012 setup_common.py
-rwxrwxrwx 1 mysql mysql 3392 Jan 2 2014 setup_posix.py
-rwxrwxrwx 1 mysql mysql 609 Jan 2 2014 setup.py
-rwxrwxrwx 1 mysql mysql 1334 Oct 8 2012 setup_windows.py
-rwxrwxrwx 1 mysql mysql 665 Oct 8 2012 site.cfg
drwxrwxrwx 1 mysql mysql 4096 Sep 18 10:17 tests
[root@docker1 MySQL-python-1.2.5]# python setup.py install
...
_mysql.c:44:23: fatal error: my_config.h: No such file or directory
 #include "my_config.h"
                       ^
compilation terminated.
error: command 'gcc' failed with exit status 1
 
    After that,I search for a workaround in google,someone says that I need't to install mysql-devel package first:
 
[root@docker1 MySQL-python-1.2.5]# yum install mysql-devel
...
Error: mariadb101u-common conflicts with 1:mariadb-libs-5.5.60-1.el7_5.x86_64
Error: mariadb101u-config conflicts with 1:mariadb-libs-5.5.60-1.el7_5.x86_64
Error: mariadb101u-libs conflicts with 1:mariadb-libs-5.5.60-1.el7_5.x86_64
 You could try using --skip-broken to work around the problem
 You could try running: rpm -Va --nofiles --nodigest
 
    There were some confilcts with package mariadb-llibs when installing mysql-devel package.Then I have to erase it first:
 
[root@docker1 MySQL-python-1.2.5]# rpm -e mariadb-libs
error: Failed dependencies:
 libmysqlclient.so.18()(64bit) is needed by (installed) perl-DBD-MySQL-4.023-6.el7.x86_64
 libmysqlclient.so.18()(64bit) is needed by (installed) python27-MySQL-python-1.2.3-11.el7.x86_64
 libmysqlclient.so.18(libmysqlclient_18)(64bit) is needed by (installed) perl-DBD-MySQL-4.023-6.el7.x86_64
 libmysqlclient.so.18(libmysqlclient_18)(64bit) is needed by (installed) python27-MySQL-python-1.2.3-11.el7.x86_64
[root@docker1 MySQL-python-1.2.5]# rpm -e --force mariadb-libs 
rpm: only installation and upgrading may be forced
rpm -e -Va --nofiles --nodigest mariadb-libs
[root@docker1 MySQL-python-1.2.5]# rpm -e --nodeps mariadb-libs
warning: /etc/my.cnf saved as /etc/my.cnf.rpmsave
 
    After I've erased the package of mariadb-lib,the my.cnf will be saved as my.cnf.rpmnew and my.cnf.rpmsave.The default my.cnf was missing.
 
[root@docker1 etc]# ll|grep my
-rw-r--r-- 1 mysql mysql 2540 Sep 17 10:05 my3306.cnf
-rw-r--r-- 1 root root 570 Aug 16 22:00 my.cnf.rpmnew
-rw-r--r-- 1 root root 83 Sep 12 13:34 my.cnf.rpmsave
[root@docker1 etc]# cat my.cnf
cat: my.cnf: No such file or directory
 
    And then the afterward installation was extremly successful.
 
[root@docker1 MySQL-python-1.2.5]# yum install mysql-devel
...
Installed:
  mariadb101u-devel.x86_64 1:10.1.32-1.ius.centos7                                                                                                   
 
Dependency Installed:
  mariadb101u-common.x86_64 1:10.1.32-1.ius.centos7 mariadb101u-config.x86_64 1:10.1.32-1.ius.centos7                        
  mariadb101u-libs.x86_64 1:10.1.32-1.ius.centos7                          
 
Complete!
[root@docker1 MySQL-python-1.2.5]# 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-python
  Running setup.py install for mysql-python ... done
Successfully installed mysql-python-1.2.5
[root@docker1 MySQL-python-1.2.5]#

安装MySQLdb模块遭遇"fatal error: my_config.h: No such file or directory"的处理的更多相关文章

  1. ubuntu 安装 regex模块时 fatal error: Python.h: No such file or directory

    原因是 python-dev包没有安装 根据Py2还是py3 sudo apt-get install python-dev 或者 sudo apt-get install python3-dev 安 ...

  2. Centos 7.5源码编译安装zabbix4.0报fatal error: mysql.h: No such file or directory

    系统环境:CentOS 7.5是最小化安装的 编译信息 编译选项: root@Server01 zabbix-]# ./configure --prefix=/usr/share/applicatio ...

  3. Centos pip 安装uwsgi 报错“fatal error: Python.h: No such file or directory”

    解决方法: 安装python-devel即可,注意,不是python-dev yum -y install python-devel

  4. qingstor python-sdk 安装错误 src/MD2.c:31:20: fatal error: Python.h: No such file or directory

    ubuntu安装python qingstor-sdk, src/MD2.c:31:20: fatal error: Python.h: No such file or directory compi ...

  5. 解决 Boost安装:fatal error: bzlib.h: No such file or directory 问题

    参考: How to install all the boost development libraries? 解决 Boost安装:fatal error: bzlib.h: No such fil ...

  6. plugins/python/uwsgi_python.h:2:20: fatal error: Python.h: No such file or directory

    装一台新服务器环境的时候,装uwsgi报错: plugins/python/uwsgi_python.h:2:20: fatal error: Python.h: No such file or di ...

  7. [lua]luasocket.c:20:17: fatal error: lua.h: No such file or directory

    安装luasocket的时候出现了如下的错误 问题 $ tar xzf luasocket-2.0.2.tar.gz $ cd luasocket-2.0.2 $ $ make cd src; mak ...

  8. Ubuntu下 fatal error: Python.h: No such file or directory 解决方法

    参考: fatal error: Python.h: No such file or directory Ubuntu下 fatal error: Python.h: No such file or ...

  9. tesseract编译错误:fatal error: allheaders.h: No such file or directory

    错误描述: globaloc.cpp::: fatal error: allheaders.h: No such file or directory #include "allheaders ...

随机推荐

  1. 关于PHP上传文件失败但是找不到原因的问题?

    确定上传文件的前后台代码都准确无误后,可以考虑是不是PHP配置文件中限制了上传文件的大小 1.找到根目录中的PHP文件夹 2.点击当前正在使用的的PHP版本 3.搜索php.ini 4.打开 phpF ...

  2. vue - 简单实例(vue-router + webpack + vuex)

    分享 + 实践  基于公司部分产品技术栈转型使用vue,部分同事需要学习一下,快速上手,那么我很荣幸的成为了给大家分享vue技术栈的‘ ’导师‘,在这里我分享一下: 讲解大纲为:(我是有一份PPT的, ...

  3. 十三、IntelliJ IDEA 中的版本控制介绍(下)

    我们已经简单了解了 IntelliJ IDEA 的版本控制机制,那么接下来,就让我们一起看看在 IntelliJ IDEA 中进行具体的版本控制操作. 标注1:Checkout from Versio ...

  4. 通过Field (反射)给私有字段赋值

    public class Person { public String name; public char sex; private int age; public String getName() ...

  5. PAT——1016. 部分A+B

    正整数A的“DA(为1位整数)部分”定义为由A中所有DA组成的新整数PA.例如:给定A = 3862767,DA = 6,则A的“6部分”PA是66,因为A中有2个6. 现给定A.DA.B.DB,请编 ...

  6. 用DecimalFormat格式化十进制数字的实际应用

    在项目中,有时候我们需要将数字转换成特定的格式便于操作和使用.最常用的就是在操作价格数字的时候,需要将数字转换成小数点后保留两位小数,比如讲3.4转换成3.40 我们可以用DecimalFormat, ...

  7. 【Linux学习笔记】Linux-CentOS下安装Redis

    虚机装了个Linux,尝试安装了一下Redis这款NoSQL数据库玩玩,作为Linux小白,我安装的是有可视化桌面的CentOS,所以不是纯命令行操作,怎么方便怎么来嘛~ 1.官网下载Redis到指定 ...

  8. Google Performance工具,你还不会用?Git走起。

    2018俄罗斯世界杯如火如荼的进行中,第一轮各种冷门,让大家的确大跌眼界,尤其是那些买球的同志们,慌得一笔,还敢继续买吗?话说来,看球归看球,学习还是不能落下,我们来学习Chrome Devtool ...

  9. javascript中sort()排序的一些理解

    sort()方法对一个数组进行排序,并可以接受一个比较函数,最后返回一个排序的数组. 1.sort()有自身默认的比较函数,该函数把排序的元素都看作字符串. var s = [5, 4, 3, 2, ...

  10. LightOJ 1203--Guarding Bananas(二维凸包+内角计算)

    1203 - Guarding Bananas    PDF (English) Statistics Forum Time Limit: 3 second(s) Memory Limit: 32 M ...