or

How to Install Python MySQL Egg on OS X

Yesterday I started a project using Django and I wanted to use MySQL. Since I bought my Mac a month ago, I didn’t get chance to install all Python MySQL egg. Then I noticed that Leopard has some issues with installing Python MySQL egg. I don’t know maybe it was because of changing to Python 2.6. Anyways, here is how I solved my problem after a little googling.

If you are having same problem installing (even with MacPorts), here is how you do:

First of all, you need to download the actual source for mysql-python. I used MySQL-python-1.2.2 version. Then extract the contents of the file to a location, and open this location up in the Terminal.

From this point, it’s going to be a little tricky. You need to edit _mysql.c file. Open the file in any text editor and remove following lines somewhere close to line 40:

#ifndef uint
#define uint unsigned int
#endif

And change the following lines (line 480ish):

uint port = MYSQL_PORT;
uint client_flag = 0;

#change above lines to
unsigned int port = MYSQL_PORT;
unsigned int client_flag = 0;

Create a symbolic link to all of the files in the lib directory under a directory called mysql in lib by:

$ sudo ln -s /usr/local/mysql/lib /usr/local/mysql/lib/mysql

After this step, you need to build the egg again and install it:

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

That’s it. I hope it helps..

Edit: Make sure you’re using 32bit version of MySQL



One Response

  1. Stu Thompson

    Hi, thanks for the post. It seems that this has been resolved with MySQL-python-1.2.3c1, at least the edit of _mysql.c part.

    Regardless, I’m back in action. Thanks.

    Stu

    August 5, 2009, 12:05 AM

Leave a Reply

Name (required)
Mail (required)
Website