在Python安装MySQLdb模块遇见的问题

来源:互联网 发布:sqlserver删除表数据 编辑:程序博客网 时间:2024/06/12 16:24

安装python2.7的MySQLdb模块时遇见如下问题:
[root@mycat-1 MySQL-python-1.2.3b1]# python setup.py build
running build
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-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,3,’beta’,1) -D__version__=1.2.3b1 -I/home/mycat/mysql_5717/include -I/usr/include/python2.7 -c _mysql.c -o build/temp.linux-x86_64-2.7/_mysql.o -fabi-version=2 -fno-omit-frame-pointer
_mysql.c:35: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

看网上说要安装mysql-devel:

yum install -y mysql-devel

但是安装之后还是报同样的错误
执行:which mysql_config

[root@mycat-1 MySQL-python-1.2.3b1]# which mysql_config/home/mycat/mysql_5717/bin/mysql_config

我感觉我发现问题了,可能是我yum安装mysql-devel、mysql的版本与PATH路径下的mysql_config版本有冲突
修改PATH中mysql_config路径,改外/usr/bin/mysql_conifg之后,再进行安装,成功了。
tips:还可以通过修改setup_posix.py中mysql_config.path直接改为/usr/local/mysql_config来解决版本冲突问题。