MacOS X 安装 Python MySQLdb 时出错

2 投票
1 回答
3633 浏览
提问于 2025-04-16 00:16

我在我的Mac上尝试安装python mysqldb,但遇到了以下错误。我使用的是MAMP自带的mysql。谢谢!

这是错误信息:

running build
running build_py
copying MySQLdb/release.py -> build/lib.darwin-8.11.1-i386-2.3/MySQLdb
running build_ext
building '_mysql' extension
gcc -fno-strict-aliasing -Wno-long-double -no-cpp-precomp -mno-fused-madd -fno-common -dynamic -DNDEBUG -g -O3 -Wall -Wstrict-prototypes -Dversion_info=(1,2,3,'final',0) -D__version__=1.2.3 -I/Applications/MAMP/Library/include/mysql -I/System/Library/Frameworks/Python.framework/Versions/2.3/include/python2.3 -c _mysql.c -o build/temp.darwin-8.11.1-i386-2.3/_mysql.o
_mysql.c:36:23: error: my_config.h: No such file or directory
_mysql.c:38:19: error: mysql.h: No such file or directory
_mysql.c:39:26: error: mysqld_error.h: No such file or directory
_mysql.c:40:20: error: errmsg.h: No such file or directory
_mysql.c:76: error: parse error before 'MYSQL'
_mysql.c:76: warning: no semicolon at end of struct or union
_mysql.c:79: error: parse error before '}' token
_mysql.c:79: warning: type defaults to 'int' in declaration of '_mysql_ConnectionObject'
_mysql.c:79: warning: data definition has no type or storage class

....

1 个回答

3

我想说,单靠MAMP自带的MySQL是不够的,因为它里面没有MySQL的C开发工具(也就是一些头文件,比如mysql.h)。这里有一个关于如何在Mac OS X上编译Python的MySQL扩展的详细教程,不过看起来你需要下载“官方”的MySQL版本才能做到这一点。

撰写回答