今天在安装python的模块MySQLdb时,在编译源码时,一直出现一个错误:
error: my_config.h: No such file or directory
error: command ‘gcc’ failed with exit status 1
下面是编译信息:
# cd /usr/local/MySQL-python-1.2.5 && python setup.py install running install running bdist_egg running egg_info writing MySQL_python.egg-info/PKG-INFO writing top-level names to MySQL_python.egg-info/top_level.txt writing dependency_links to MySQL_python.egg-info/dependency_links.txt reading manifest file 'MySQL_python.egg-info/SOURCES.txt' reading manifest template 'MANIFEST.in' writing manifest file 'MySQL_python.egg-info/SOURCES.txt' installing library code to build/bdist.linux-x86_64/egg running install_lib running build_py copying MySQLdb/release.py -> build/lib.linux-x86_64-2.7/MySQLdb running build_ext building '_mysql' extension gcc -pthread -fno-strict-aliasing -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -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/opt/rh/python27/root/usr/include/python2.7 -c _mysql.c -o build/temp.linux-x86_64-2.7/_mysql.o -m64 -m64 _mysql.c:44:23: error: my_config.h: No such file or directory error: command 'gcc' failed with exit status 1
在网上找了好长时间,一直不知道什么原因,终于找到了解决的方案:
先安装mysql-devel,mysql-devel为编译mysql相关客户程序所需的库和包含文件,如果你想要编译其他MySQL客户程序,就必须先安装mysql-devel,
sudo yum install mysql-devel -y
但是在安装mysql-devel的时候又出现如下的报错:
# yum install mysql-devel ..... ---> Package nspr.x86_64 0:4.13.1-1.el6 will be updated ---> Package nspr.x86_64 0:4.21.0-1.el6_10 will be an update ---> Package nss-util.x86_64 0:3.28.4-1.el6_9 will be updated ---> Package nss-util.x86_64 0:3.44.0-1.el6_10 will be an update --> Finished Dependency Resolution Error: Multilib version problems found. This often means that the root cause is something else and multilib version checking is just pointing out that there is a problem. Eg.: 1. You have an upgrade for mysql-libs which is missing some dependency that another package requires. Yum is trying to solve this by installing an older version of mysql-libs of the different architecture. If you exclude the bad architecture yum will tell you what the root cause is (which package requires what). You can try redoing the upgrade with --exclude mysql-libs.otherarch ... this should give you an error message showing the root cause of the problem. 2. You have multiple architectures of mysql-libs installed, but yum can only see an upgrade for one of those arcitectures. If you don't want/need both architectures anymore then you can remove the one with the missing update and everything will work. 3. You have duplicate versions of mysql-libs installed already. You can use "yum check" to get yum show these errors. ...you can also use --setopt=protected_multilib=false to remove this checking, however this is almost never the correct thing to do as something else is very likely to go wrong (often causing much more problems). Protected multilib versions: mysql-libs-5.1.73-8.el6_8.i686 != mysql-libs-5.5.50-1.el6.remi.x86_64
从报错信息看,是已经存在了多版本的mysql-lib库,所以需要卸载旧版本,所以我们执行如下命令卸载mysql-libs-5.5.50
# yum remove mysql-libs-5.5.50* -y
卸载完成后,重新安装mysql-devel的时候,又出现如下的报错信息:
# yum install mysql-devel Setting up Install Process Resolving Dependencies --> Running transaction check ---> Package mysql-devel.x86_64 0:5.1.73-8.el6_8 will be installed --> Processing Dependency: mysql = 5.1.73-8.el6_8 for package: mysql-devel-5.1.73-8.el6_8.x86_64 --> Running transaction check ---> Package mysql.x86_64 0:5.1.73-8.el6_8 will be installed --> Processing Dependency: mysql-libs = 5.1.73-8.el6_8 for package: mysql-5.1.73-8.el6_8.x86_64 --> Running transaction check ---> Package mysql-libs.x86_64 0:5.1.73-8.el6_8 will be installed --> Finished Dependency Resolution Dependencies Resolved ==================================================================================================================================================== Package Arch Version Repository Size ==================================================================================================================================================== Installing: mysql-devel x86_64 5.1.73-8.el6_8 base 130 k Installing for dependencies: mysql x86_64 5.1.73-8.el6_8 base 895 k mysql-libs x86_64 5.1.73-8.el6_8 base 1.2 M Transaction Summary ==================================================================================================================================================== Install 3 Package(s) Total size: 2.2 M Installed size: 6.8 M Is this ok [y/N]: y Downloading Packages: Running rpm_check_debug Running Transaction Test Transaction Check Error: file /usr/lib64/mysql/libmysqlclient.so.16.0.0 from install of mysql-libs-5.1.73-8.el6_8.x86_64 conflicts with file from package compat-mysql51-5.1.54-1.el6.remi.x86_64 file /usr/lib64/mysql/libmysqlclient_r.so.16.0.0 from install of mysql-libs-5.1.73-8.el6_8.x86_64 conflicts with file from package compat-mysql51-5.1.54-1.el6.remi.x86_64 Error Summary
从提示的报错信息看,是由于包冲突引起的!
所以先移除冲突的compat-mysql51-5.1.54包。再进行安装。
# yum -y remove compat-mysql51-5.1.54*
冲突的包移除之后,然后重新安装mysql-devel包,安装完成后,重新编译MySQL-python
然后正常执行:
python setup.py build python setup.py install
安装完成后,执行python -c “import MySQLdb”没有任何输出,说明MySQLdb安装成功;