【问题标题】:Help installing MySQLdb for Python under Mac OS X帮助在 Mac OS X 下安装 MySQLdb for Python
【发布时间】:2011-08-24 14:49:44
【问题描述】:

我知道这个问题已经被问过好几次了,但是经过几个小时的尝试,没有办法让它工作。

我已经从 dmg 文件和 MySQL-python-1.2.3 安装了 MySQL 32bits。

我关注了this steps,但是当我运行python setup.py build时,出现了这些错误:

running build
running build_py
copying MySQLdb/release.py -> build/lib.macosx-10.6-fat-2.6/MySQLdb
running build_ext
building '_mysql' extension
gcc-4.2 -fno-strict-aliasing -fno-common -dynamic -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -pipe -Dversion_info=(1,2,3,'final',0) -D__version__=1.2.3 -I/usr/local/mysql-5.5.12-osx10.6-x86/include -I/System/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6 -c _mysql.c -o build/temp.macosx-10.6-fat-2.6/_mysql.o -Os -g -fno-common -fno-strict-aliasing -arch i386
In file included from _mysql.c:36:
/usr/local/mysql-5.5.12-osx10.6-x86/include/my_config.h:326:1: warning: "SIZEOF_SIZE_T" redefined
In file included from /System/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6/Python.h:9,
                 from pymemcompat.h:10,
                 from _mysql.c:29:
/System/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6/pymacconfig.h:39:1: warning: this is the location of the previous definition
In file included from _mysql.c:36:
/usr/local/mysql-5.5.12-osx10.6-x86/include/my_config.h:419:1: warning: "HAVE_WCSCOLL" redefined
In file included from /System/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6/Python.h:8,
                 from pymemcompat.h:10,
                 from _mysql.c:29:
/System/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6/pyconfig.h:803:1: warning: this is the location of the previous definition
_mysql.c:76: error: expected specifier-qualifier-list before ‘MYSQL’
_mysql.c:90: error: expected specifier-qualifier-list before ‘MYSQL_RES’
_mysql.c: In function ‘_mysql_Exception’:
_mysql.c:120: warning: implicit declaration of function ‘mysql_errno’
_mysql.c:120: error: ‘_mysql_ConnectionObject’ has no member named ‘connection’
_mysql.c:132: error: ‘ER_DB_CREATE_EXISTS’ undeclared (first use in this function)
_mysql.c:132: error: (Each undeclared identifier is reported only once

......

如果您能提供任何帮助,我将不胜感激。谢谢!

【问题讨论】:

标签: python mysql macos mysql-python


【解决方案1】:

试试macports:

$ port search python | grep mysql
py-mysql @1.2.2 (python, devel, databases)
Python interface to mysql
py25-mysql @1.2.2 (python, devel, databases)
Python interface to mysql
py26-mysql @1.2.3 (python, devel, databases)
py27-mysql @1.2.2 (python, devel, databases)
Python interface to mysql

【讨论】:

  • 嘿,谢谢!不过,我不知道 100% 我刚刚做了什么:D 如果我从 Python CLI 运行“import MySQLdb”,它不会找到它。如何检查它是否正确安装?
  • 该命令不会安装它。不过,sudo port install py-mysql(或您想要的任何一个)会。 port list | grep py-mysql 会显示它是否已安装。
  • 是的,我现在知道了,我正在安装,看看效果如何。谢谢。
【解决方案2】:

如果你不想在你的 mac 上处理包管理器的问题,我在本安装指南中详细介绍了我的经验:http://alexandersimoes.com/journal/2011/03/04/install-mysqldb-on-mac-osx-snow-leopard/

【讨论】:

  • 这非常有帮助。谢谢。
【解决方案3】:

我的回答对我来说适用于 32 位和 64 位 Mac Snow Leopard 安装(在两台不同的机器上):Installing MySQLdb for Django on Mac OS X 10.6 Snow Leopard with MAMP

短版:

[user]$ sudo su
[root]# ARCHFLAGS="-arch $(uname -m)" pip install mysql-python

【讨论】:

    猜你喜欢
    • 2011-07-28
    • 2014-11-19
    • 1970-01-01
    • 2011-09-08
    • 2011-05-08
    • 2012-09-18
    • 1970-01-01
    • 2011-06-24
    • 1970-01-01
    相关资源
    最近更新 更多