views:

247

answers:

1

I'm running a database server in a Linux VM (Ubuntu 9.10) under VMware Fusion, but coding Django on the Mac side. Installing mysql-python requires that MySQL is installed on the Mac for compiling _mysql.so into site-packages.

However, after this is done, I have no further use for MySQL on the Mac side, and would rather just delete it. Of course, this is not possible when _mysql.so requires /usr/local/mysql/lib/libmysqlclient_r.16.dylib.

There is a "static" option in mysql-python's site.cfg, which, when set to "true", significantly increases the size of the _mysql.so file, but it still depends on the .dylib.

Is there a way of making the .so completely independent of whether MySQL is installed or not, even if that means making the file enormous?

The solution, if one exists, should work on both 10.5 and 10.6, since I'll be using both versions on different machines for the time being.

+1  A: 

Never mind, found out myself after a bit more digging. It's pretty simple, actually; I'll record the solution here in case someone else needs it:

  1. Get the source tarball of MySQL from mysql.com (not the platform-specific binary tarball)

  2. Unpack it, run ./configure with whatever options suit your purposes, but you will require --enable-static. Just to be sure, I included --disable-shared, though it might not be strictly necessary. I used the following, yours might differ on other counts:

    $ ./configure --prefix=/usr/local/mysql-src/ --enable-static --disable-shared --with-charset=utf8 --with-extra-charsets=ascii,binary,latin1 --with-collation=utf8_general_ci
    $ make
    $ sudo make install

    (Regarding the charset and collation parameters here: they may be completely unnecessary in this use case, since I'm going to delete MySQL afterwards, but since all the client connections use some charset/collation, I'm covering my bases UTF-8 -wise just in case the default charset/collation used by MySQLdb is affected by how _mysql.so is compiled -- wiser men than I may want to confirm this one way or the other.)

  3. Get the latest source tarball of mysql-python from http://pypi.python.org/pypi/MySQL-python

  4. Unpack it, and in site.cfg set static = True and mysql_config = /usr/local/mysql-src/bin/mysql_config (or whatever path you chose during configure).

  5. Run python setup.py build. Some architecture-related errors may appear at the end of the compile, but they can be ignored.

  6. Run sudo python setup.by install. This creates an .egg in your site-packages directory and adds it to the easy_install.pth file.

  7. You're done! You may now delete all traces of MySQL as well as the mysql-python sources. The egg can be copied as-is to other Macs running the same version of OS X. I'm happily copying it to various virtual environments created with virtualenv as we speak.

This worked on 10.5, I'll test it on 10.6 soon and, if something needs to be done differently, report the results here.

JK Laiho
Worked fine on 10.6 as instructed.
JK Laiho
I found out that `--disable-shared` is required for a static build.
Sridhar Ratnakumar