views:

966

answers:

3

Hi All I am having a problem installing the Python MySQL connector (MySQL-python-1.2.3c1) on my Mac OSX Snow Leopard.

System State

I have manually compiled an installed: mysql-5.1.41

This seems to work fine, as I can create and query a database from the commandline.

I have compiled: MySQL-python-1.2.3c1

I first set the following in the site.cfg file:

mysql_config = /usr/local/mysql/bin/mysql_config

I then built and compiled MySQL-python-1.2.3c1 following their guide:

sudo python setup.py build
sudo python setup.py install

I now test the installation with Python:

python -c "import MySQLdb"

Error Message

This then gives me the following error, and I'm stumped as to how to fix it:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "build/bdist.macosx-10.6-universal/egg/MySQLdb/__init__.py", line 19, in <module>
  File "build/bdist.macosx-10.6-universal/egg/_mysql.py", line 7, in <module>
  File "build/bdist.macosx-10.6-universal/egg/_mysql.py", line 6, in __bootstrap__
ImportError: dlopen(/Users/username/.python-eggs/MySQL_python-1.2.3c1-py2.6-macosx-10.6-universal.egg-tmp/_mysql.so, 2): Symbol not found: _mysql_affected_rows
  Referenced from: /Users/username/.python-eggs/MySQL_python-1.2.3c1-py2.6-macosx-10.6-universal.egg-tmp/_mysql.so
  Expected in: flat namespace
 in /Users/username/.python-eggs/MySQL_python-1.2.3c1-py2.6-macosx-10.6-universal.egg-tmp/_mysql.so
mymac: username$

Things I've Tried

I've looked at this blog antoniocangiano.com but it is for an older version of MySQL-python and is not really applicable. But I tried adding the soft link it mentions.

I then looked at this blog post: http://blog.some-abstract-type.com/2009/09/mysql-python-and-mac-os-x-106-snow.html. And tried building compiling with the ARCHFLAGS settings - but no joy.

Please Help

If you have any ideas please let me know.

Many thanks

Ben...

+1  A: 

What does

otool -L /Users/username/.python-eggs/MySQL_python-1.2.3c1-py2.6-macosx-10.6-universal.egg-tmp/_mysql.so

report?

thouis
Hi thouisIt gives me the following: /Users/username/.python-eggs/MySQL_python-1.2.3c1-py2.6-macosx-10.6-universal.egg-tmp/_mysql.so: /usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.3) /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 125.0.0)
emson
Glad it got fixed.As it turns out, the command I suggested was not informative, as there's a static library for libmysqlclient, and _mysql.so is built with "-undefined dynamic_lookup" which prevents missing symbols from being detected at compile time. The default build options for MySQLdb seem to be to use the .dylib, so perhaps only the static library was installed initially.As a note to future readers: it's often a good idea to remove the build directory completely before running setup.py build. (setup.py clean may not be enough, particularly if the ARCH flags are changed).
thouis
+3  A: 

First, I would suggest using the MySQL binaries for MacOS X 10.5 64-bit (x86_64). The tar ball works on MacOS X 10.6.

You said you used ARCHFLAGS.. however, try it again like this:

shell> ARCHFLAGS="-arch x86_64" python setup.py build
shell> sudo python setup.py install

Thus building as normal user, installing as root. (It's good to remove the source, and unpack correcting the site.cfg file again).

geertjanvdk
Awesome, this worked I'll put my notes below.
emson
I just removed the old version of the MySQL-python-1.2.3c1.Then extracted the tar ball again and modified the site.cfg file. This time I left the mysql_config commented out as it is in my $PATH.I then ran the your commands above and it worked fine.Thanks very much... PS I like your blog.Ben...
emson
A: 

Following these instructions, I get:

raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e) django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: dynamic module does not define init function (init_mysql)

When I try to import.

Any ideas on this?

Thanks,

S