2011-05-13 58 views
1

我知道這已經被問了好幾次了,但經過幾個小時的嘗試之後,沒有辦法做到這一點。幫助在Mac OS X下爲Python安裝MySQLdb

我已經從dmg文件和MySQL-python-1.2.3安裝了MySQL 32位。

我跟着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 

......

我會很感激任何幫助,您可以提供。謝謝!

+0

看起來編譯器無法找到MySQL頭文件。頭部文件是否包含在您安裝的DMG中?如果是這樣,您可以通過設置CFLAGS環境變量將編譯器指向正確的方向。 – Dan 2011-05-15 23:40:32

+0

它包含幾個pkg文件來安裝它... – Nacho 2011-05-15 23:43:00

+0

可能重複[如何在Mac OS X上安裝MySQLdb(Python數據訪問庫到MySQL)](http://stackoverflow.com/questions/1448429/how -to-install-mysqldb-python-data-access-library -to-mysql-on-mac-os-x) – Mark 2011-12-17 22:53:29

回答

6

嘗試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 
+0

嘿,謝謝!但我不知道100%我做了什麼,但是:D如果我從Python CLI運行「導入MySQLdb」,它不會找到它。我如何檢查它是否安裝正確? – Nacho 2011-05-15 23:40:20

+0

該命令不會安裝它。儘管如此,'sudo port install py-mysql'(或者你想要的任何一個)都可以。和'端口列表| grep py-mysql'會顯示它是否安裝。 – 2011-05-15 23:50:06

+0

是的,我現在明白了,我正在安裝,看看它是如何發展的。謝謝。 – Nacho 2011-05-15 23:54:52