views:

433

answers:

5

i remember installing Python + Django + MySQL + MySQLdb on my 32-bit Mac with Leopard 10.5.7. I tried the same procedure with Mac Snow Leopard. But have unfortunately ran into a lot of errors... i dont know but something weird is happening. Please look at the error log:

Amit-Vermas-MacBook:mysql-python-1.2.2 amitverma$ python setup.py build
running build
running build_py
copying MySQLdb/release.py -> build/lib.macosx-10.3-i386-2.5/MySQLdb
running build_ext
building '_mysql' extension
creating build/temp.macosx-10.3-i386-2.5
gcc-4.0 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -fno-strict-aliasing -Wno-long-double -no-cpp-precomp -mno-fused-madd -fno-common -dynamic -DNDEBUG -g -O3 -Dversion_info=(1,2,2,'final',0) -D__version__=1.2.2 -I/usr/local/mysql/include -I/Library/Frameworks/Python.framework/Versions/2.5/include/python2.5 -c _mysql.c -o build/temp.macosx-10.3-i386-2.5/_mysql.o -g -Os -arch x86_64 -fno-common -D_P1003_1B_VISIBLE -DSIGNAL_WITH_VIO_CLOSE -DSIGNALS_DONT_BREAK_READ -DIGNORE_SIGHUP_SIGQUIT -DDONT_DECLARE_CXA_PURE_VIRTUAL
In file included from /Library/Frameworks/Python.framework/Versions/2.5/include/python2.5/Python.h:57,
                 from pymemcompat.h:10,
                 from _mysql.c:29:
/Library/Frameworks/Python.framework/Versions/2.5/include/python2.5/pyport.h:761:2: error: #error "LONG_BIT definition appears wrong for platform (bad gcc/glibc config?)."
In file included from _mysql.c:35:
/usr/local/mysql/include/my_config.h:1050:1: warning: "HAVE_WCSCOLL" redefined
In file included from /Library/Frameworks/Python.framework/Versions/2.5/include/python2.5/Python.h:8,
                 from pymemcompat.h:10,
                 from _mysql.c:29:
/Library/Frameworks/Python.framework/Versions/2.5/include/python2.5/pyconfig.h:721:1: warning: this is the location of the previous definition
In file included from _mysql.c:35:
/usr/local/mysql/include/my_config.h:1168:1: warning: "SIZEOF_LONG" redefined
In file included from /Library/Frameworks/Python.framework/Versions/2.5/include/python2.5/Python.h:8,
                 from pymemcompat.h:10,
                 from _mysql.c:29:
/Library/Frameworks/Python.framework/Versions/2.5/include/python2.5/pyconfig.h:811:1: warning: this is the location of the previous definition
In file included from _mysql.c:35:
/usr/local/mysql/include/my_config.h:1177:1: warning: "SIZEOF_PTHREAD_T" redefined
In file included from /Library/Frameworks/Python.framework/Versions/2.5/include/python2.5/Python.h:8,
                 from pymemcompat.h:10,
                 from _mysql.c:29:
/Library/Frameworks/Python.framework/Versions/2.5/include/python2.5/pyconfig.h:820:1: warning: this is the location of the previous definition
error: command 'gcc-4.0' failed with exit status 1
Amit-Vermas-MacBook:mysql-python-1.2.2 amitverma$
A: 

There are a few other stack overflow threads on MySQldb on snow leopard. Perhaps look at them?

extraneon
its really confusing. i am new to the mac platform and i really dont understand how to go about it...
amit
A: 

The following blog post helped me compile MySQLdb 1.2.2 on the Mac: http://www.mangoorange.com/2008/08/01/installing-python-mysqldb-122-on-mac-os-x/

However, later on I tried MySQLDB 1.2.3c1 and didn't have any problems compiling out of the box. 1.2.2 is several years old and causes deprecation warnings on Python 2.6. I would just make the switch to 1.2.3.c1 and see if that works for you.

1.2.3c1 is the latest version on PyPi.

ara818
+1  A: 

This is my personal makefile rule for that

MYSQLDB_VERSION=1.2.3c1
MYSQLDB_TARGET=$(BUILD_FLAGS_DIR)/mysqldb
MYSQLDB_PACKAGE=MySQL-python-$(MYSQLDB_VERSION).tar.gz
MYSQLDB_PACKAGE_URL=http://downloads.sourceforge.net/project/mysql-python/mysql-python-test/$(MYSQLDB_VERSION)/$(MYSQLDB_PACKAGE)

.PHONY: mysqldb mysqldb-download
mysqldb: $(MYSQLDB_TARGET)
mysqldb-download: $(DOWNLOAD_DIR)/$(MYSQLDB_PACKAGE)

$(MYSQLDB_TARGET): $(INIT_TARGET) $(MYSQLDB_DEPS) $(DOWNLOAD_DIR)/$(MYSQLDB_PACKAGE)
    -rm -rf $(UNPACK_DIR)/MySQL-python-$(MYSQLDB_VERSION)
    tar -m -C $(UNPACK_DIR) -xzvf $(DOWNLOAD_DIR)/$(MYSQLDB_PACKAGE)
    -cd $(UNPACK_DIR)/MySQL-python-$(MYSQLDB_VERSION); \
    for patch in $(PATCH_DIR)/mysqldb-$(MYSQLDB_VERSION)_$(ARCH)_*; \
        do patch -p1 < $$patch; \
    done
    cd $(UNPACK_DIR)/MySQL-python-$(MYSQLDB_VERSION); export CC="gcc -m64" FC="g95 -m64" CPPFLAGS="-I$(RUNTIME_DIR)/include" CFLAGS="-m64 -I$(RUNTIME_DIR)/include" LD_LIBRARY_PATH=$(RUNTIME_DIR)/lib64:$(RUNTIME_DIR)/lib:$$LD_LIBRARY_PATH PATH=$(RUNTIME_DIR)/bin:$$PATH PYTHONPATH=$(RUNTIME_DIR)/lib/python2.5/site-packages/; $(RUNTIME_DIR)/bin/python2.5 setup.py install --prefix=$(RUNTIME_DIR)
    touch $(MYSQLDB_TARGET)

$(DOWNLOAD_DIR)/$(MYSQLDB_PACKAGE):
    for package in $(MYSQLDB_PACKAGE_URL); \
    do \
        echo -n "Downloading $$package... ";  \
        cd $(DOWNLOAD_DIR); curl -L -O $$package; \
        echo "done"; \
    done
    touch $@

ALL_RUNTIME_TARGETS+=$(MYSQLDB_TARGET)
ALL_DOWNLOAD_TARGETS+=$(DOWNLOAD_DIR)/$(MYSQLDB_PACKAGE)

And a patch

$ more mysqldb-1.2.3c1_x86_64-apple-darwin10_patch-000 
diff -Naur MySQL-python-1.2.3c1/setup.py MySQL-python-1.2.3c1.new/setup.py
--- MySQL-python-1.2.3c1/setup.py       2008-10-18 02:12:31.000000000 +0200
+++ MySQL-python-1.2.3c1.new/setup.py   2009-10-08 22:59:05.000000000 +0200
@@ -13,6 +13,8 @@
     from setup_windows import get_config

 metadata, options = get_config()
+options["extra_compile_args"].remove("-arch")
+options["extra_compile_args"].remove("x86_64")
 metadata['ext_modules'] = [Extension(sources=['_mysql.c'], **options)]
 metadata['long_description'] = metadata['long_description'].replace(r'\n', '')
 setup(**metadata)

And it works for me. I cannot guarantee, but... maybe you will find some interesting hint inside.

Please note that I am using a custom built compiler (for outdated reasons too ugly to delve in)

Stefano Borini
hey stefano. i am afraid this is all greek to me. i am at a pretty nascent stage and the above words are just scaring me. i successfully did this on my previous 10.5.7 Mac. Now that i have 10.6 Snow Leopard, life's become hell. i think it has to do with the 64-bit thing.
amit
+1  A: 

The most likely explanation is that you are trying to link a 64-bit version of the MySQL libraries with a 32-bit-only version of Python (currently, all of the python.org installers for OS X are 32-bit only). (You can verify that by using the file command on the library files in /usr/local/mysql/).

Some solutions:

  • use the Apple-supplied python2.6 on Snow Leopard which is 64-bit

  • install a 32-bit version of the MySQL libraries

  • install a complete solution using MacPorts: install the base MacPorts infrastructure and then install the MySQLdb adapter for python 2.6 (or 2.5) which will also install all necessary dependencies including a new python and MySQL client libraries that should all work together correctly (and be able to be updated by MacPorts):

    sudo port install py26-mysql # or py25-mysql

For using MySQL with python on OS X, I recommend the last solution, that is, unless you really enjoy and have the time to do package management and installation. It will likely save you a lot of trouble over the long run.

P.S. MacPorts includes ports of django and PIL as well:

sudo port install py26-django py26-pil

EDIT:

To go the MacPorts route, follow the instructions I gave here to remove the effects of a python.org installer python. DO NOT attempt to delete or modify the Apple-installed Python files in /usr/bin or /System/Library; they are part of OS X. Then follow the instructions cited above to install MacPorts. In order to avoid interference with Apple- or third-party installs, MacPorts installs all of its files into a completely separate directory structure rooted at /opt/local. Thus, you will need to modify your .bash_profile to add /opt/local/bin to your $PATH. If you want the MacPorts versions to be found first, add something like:

export PATH="/opt/local/bin:${PATH}"

When you start a new terminal session, you should find the MacPorts python2.6 at python2.6. If you also want to make the command python point there:

$ sudo port install python_select
$ sudo python_select -l
Available versions:
current none python26 python26-apple
$ sudo python_select python26
Ned Deily
i initially installed 32-bit version of MySQL. it didnt work. then i switched to 64-bit ones. in the process i have switched from python 2.5.4 to 2.6.4 and everything in between :) it really has confused me and my mac. but i think you have a point here. now i want to do clean re-install. is there a way to remove all the versions of python installed on the system and then do a re-install?
amit
A: 

It looks like you need to reinstall/update XCode (build tools)

kibitzer