MySQL-python in Leopard.
Installing the python library for MySQL in Leopard can be a bit tricky. If you’re an easy_install lover, the first thing to try would be:
$ sudo easy_install MySQL-python
But the results you’ll obtain will be not very encouraging.
Searching for MySQL-python
Reading http://pypi.python.org/simple/MySQL-python/
Reading http://sourceforge.net/projects/mysql-python
Reading http://sourceforge.net/projects/mysql-python/
Best match: MySQL-python 1.2.2
Downloading http://downloads.sourceforge.net/mysql-python/MySQL-python-1.2.2.tar.gz
Processing MySQL-python-1.2.2.tar.gz
Running MySQL-python-1.2.2/setup.py -q bdist_egg –dist-dir /tmp/easy_install-07GTpt/MySQL-python-1.2.2/egg-dist-tmp-t78bko
In file included from /opt/local/include/mysql5/mysql/mysql.h:47,
from _mysql.c:40:
/usr/include/sys/types.h:92: error: duplicate ‘unsigned’
/usr/include/sys/types.h:92: error: two or more data types in declaration specifiers
In file included from /opt/local/include/mysql5/mysql/mysql.h:47,
from _mysql.c:40:
/usr/include/sys/types.h:92: error: duplicate ‘unsigned’
/usr/include/sys/types.h:92: error: two or more data types in declaration specifiers
lipo: can’t open input file: /var/tmp//cczla7iC.out (No such file or directory)
error: Setup script exited with error: command ‘gcc’ failed with exit status 1
But the solution is there. As you can see, the command talks about an error in line 40 for some file called _mysql.c. We’re going to get to that file and remove one line.
First we need to download the package. We will use easy_install, but later. So now grab your wget or your browser to here. And when you have the file, uncompress it (terminal or through finder).
$ wget http://downloads.sourceforge.net/mysql-python/MySQL-python-1.2.2.tar.gz
…
$ tar xzf MySQL-python-1.2.2.tar.gz
Now go to the directory that has just been created and open the file _mysql.c. Go to the line number 38.
35 #include “my_config.h”
36 #endif
37 #ifndef uint
38 #define uint unsigned int
39 #endif
40 #include “mysql.h”
Delete line 38, save and install your modified egg from the parent directory with:
$ easy_install MySQL-python-1.2.2
Processing MySQL-python-1.2.2
Running setup.py -q bdist_egg –dist-dir /Users/alff/tmp/MySQL-python-1.2.2/egg-dist-tmp-S4uIM7
ld: warning in /opt/local/lib/mysql5/mysql/libmysqlclient_r.dylib, file is not of required architecture
ld: warning in /opt/local/lib/libz.dylib, file is not of required architecture
ld: warning in /opt/local/lib/libssl.dylib, file is not of required architecture
ld: warning in /opt/local/lib/libcrypto.dylib, file is not of required architecture
zip_safe flag not set; analyzing archive contents…
Adding MySQL-python 1.2.2 to easy-install.pth file
.
Installed /Library/Python/2.5/site-packages/MySQL_python-1.2.2-py2.5-macosx-10.5-i386.egg
Processing dependencies for MySQL-python==1.2.2
Finished processing dependencies for MySQL-python==1.2.2
The problem was that _mysql.c defined the type unit and that type is defined again when it includes the file mysql.h. We remove the duplicate, the compiler is happy
Edit: If you installed mysql5 with MacPorts, and you get the error EnvironmentError: mysql_config not found when installing the egg. Just add a link from mysql_config to mysql_config5.
# which mysql_config5
/opt/local/bin/mysql_config5
# cd /opt/local/bin/
# ln -s mysql_config5 mysql_config
Tags:easy_install, leopard, Mac, mysql, mysqldb, python »
Comments (4) »
