Question

I have been assigned to maintain a tool written in Python that interfaces with MySQL. Users use this tool through different applications that uses different versions of Python.

Sometimes the Python version changes between software releases of the same application. We have no control on the application the user chooses to interact with (they all have Python interface and run under OS X though) but I got almost everything to work except for the problems with Python-MySQL. Specifically, some software uses the 64-bit versions of Python. Others come with the 32-bit version. OS X (the OS I need to support) comes with Python and Python-MySQL 32bit installed so if I try to:

import MySQLdb 

in the software that uses Python 64-bit, the import fails and the application will say that the binary of MySQL that ships with OS X is the wrong type.

I have downloaded, compiled and installed Python-MySQL as 64-bit app, but Python-MySQL uses Python eggs. It seems the egg is hard coded to point to a specific disk location. On my machine is /usr/local/lib/mysql.

If I have the 64-bit version on that path then my tool works with the applications that have Python 64-bit but all the other tools that uses a 32-bit version of Python fails. If I have the 32-bit version of MySQL at that disk location the 32-bit tools work and the 64-bit version stops doing what I need.

I have tried to create distinct eggs and have a 64-bit version of it where I change the egg to point to /usr/local/lib/mysql_x86_64 but I can't figure out how to do it. I have also tried to change the setup while compiling Python-MySQL to point to that location but I can’t find a way of doing this.

Right now I'm Googling my life away on the subject but if what I have just wrote rings a bell to anybody do you mind to enlighten me?

I'm not a Python-MySQL expert at all.

No correct solution

OTHER TIPS

Use virtualenv to create separate python environments, with different interpreters.

python-MySQLdb is linking against a certain lib that is installed on your system. Each environment can link against a different location.

There is no need to have two separate versions of MySQL client libraries on OS X. You can install a universal version that has both 32- and 64-bit binaries in the same file. Then install an instance of the MySQLdb adapter (python-mysql) to each of the Pythons you need, linking to the one universal version of the library. Unfortunately, the MySQL project for some reason does not make a universal binary available. But it is easy enough to build yourself. I recommend using a third-party package manager for OS X, like Homebrew or MacPorts. I don't know about Homebrew but I know from personal experience that it is very simple to do with MacPorts. After installing the MacPorts base, you can install MySQL and all of its dependencies with:

port install mysql5 +universal

(It's easier to just make +universal the default variant for all ports by editing /opt/local/macports/variants.conf.) That will install the MySQL client libs to /opt/local/lib/mysql5/mysql/. Then install the python-mysql packages linking to that library directory rather than any you may have installed elsewhere.

It's even easier to install a complete solution using MacPorts, that is, install a universal Python, universal MySQLdb, along with the MySQL client libraries:

port install py27-mysql +universal

but, if you don't have control over which Pythons your users are using, that probably won't be of use.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top