错误: 安装脚本因错误退出: 命令'gcc'执行失败,退出状态为1。

19

在 Fedora 14 中,我尝试在 Python 2.6 上安装 MySQL-python-1.2.3,但是出现了以下错误。

Fedora 14 默认使用 Python 2.7,而我的项目需要运行在 Python 2.6 上,因此我不能将 Python 从2.6更新到2.7。

_mysql.c:35:23: fatal error: my_config.h: No such file or directory
compilation terminated.
error: command 'gcc' failed with exit status 1

完整的错误信息如下

[root@localhost MySQL-python-1.2.2]# python setup.py build
running build
running build_py
creating build
creating build/lib.linux-i686-2.6
copying _mysql_exceptions.py -> build/lib.linux-i686-2.6
creating build/lib.linux-i686-2.6/MySQLdb
copying MySQLdb/__init__.py -> build/lib.linux-i686-2.6/MySQLdb
copying MySQLdb/converters.py -> build/lib.linux-i686-2.6/MySQLdb
copying MySQLdb/connections.py -> build/lib.linux-i686-2.6/MySQLdb
copying MySQLdb/cursors.py -> build/lib.linux-i686-2.6/MySQLdb
copying MySQLdb/release.py -> build/lib.linux-i686-2.6/MySQLdb
copying MySQLdb/times.py -> build/lib.linux-i686-2.6/MySQLdb
creating build/lib.linux-i686-2.6/MySQLdb/constants
copying MySQLdb/constants/__init__.py -> build/lib.linux-i686-2.6/MySQLdb/constants
copying MySQLdb/constants/CR.py -> build/lib.linux-i686-2.6/MySQLdb/constants
copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.linux-i686-2.6/MySQLdb/constants
copying MySQLdb/constants/ER.py -> build/lib.linux-i686-2.6/MySQLdb/constants
copying MySQLdb/constants/FLAG.py -> build/lib.linux-i686-2.6/MySQLdb/constants
copying MySQLdb/constants/REFRESH.py -> build/lib.linux-i686-2.6/MySQLdb/constants
copying MySQLdb/constants/CLIENT.py -> build/lib.linux-i686-2.6/MySQLdb/constants
running build_ext
building '_mysql' extension
creating build/temp.linux-i686-2.6
gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -Dversion_info=(1,2,2,'final',0) -D__version__=1.2.2 -I/usr/include/mysql -I/usr/local/include/python2.6 -c _mysql.c -o build/temp.linux-i686-2.6/_mysql.o -g -pipe -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m32 -fasynchronous-unwind-tables -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -fno-strict-aliasing -fwrapv -fPIC -DUNIV_LINUX
_mysql.c:35:23: fatal error: my_config.h: No such file or directory
compilation terminated.
error: command 'gcc' failed with exit status 1
[root@localhost MySQL-python-1.2.2]# python2.6 setup.py build
running build
running build_py
copying MySQLdb/release.py -> build/lib.linux-i686-2.6/MySQLdb
running build_ext
building '_mysql' extension
gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -Dversion_info=(1,2,2,'final',0) -D__version__=1.2.2 -I/usr/include/mysql -I/usr/local/include/python2.6 -c _mysql.c -o build/temp.linux-i686-2.6/_mysql.o -g -pipe -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m32 -fasynchronous-unwind-tables -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -fno-strict-aliasing -fwrapv -fPIC -DUNIV_LINUX
_mysql.c:35:23: fatal error: my_config.h: No such file or directory
compilation terminated.
error: command 'gcc' failed with exit status 1
3个回答

39

你需要安装 MySQL 开发包

yum install mysql-devel

我在Arch Linux中找不到mysql-devel软件包。Arch Linux中的mysql-devel叫什么名字? - Oki Erie Rinaldi
根据谷歌的快速检查和此网站https://www.archlinux.org/packages/extra/x86_64/mysql-python/,可能是`libmariadbclient`。我以前从未使用过arch-linux。 - eos87

13

安装python-devel。这应该会有所帮助。


8
以下是解决此问题的方法:
  1. 从Python2.7的site-packages目录中复制MySQLdb文件夹到Python2.6。
  2. 还需要从Python2.7的site-packages目录中复制以下文件到Python2.6。

    _mysql.so

    _mysql_exceptions.py

    _mysql_exceptions.pyc

    _mysql_exceptions.pyo

现在尝试以下操作

>>> import MySQLdb  
>>> MySQLdb.__version__  
'1.2.3'

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接