当前位置: 移动技术网 > IT编程>脚本编程>Python > 安装MySQLdb模块遭遇"fatal error: my_config.h: No such file or directory"的处理

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

2018年09月18日  | 移动技术网IT编程  | 我要评论

反射仪,楼忠福家族,奇人奇案演员表

 

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]#

 

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网