[Answered ]-Mysqldb build error

1👍

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)

1👍

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

0👍

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

0👍

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

Leave a comment