[Tutor] [OT] MySQLdb on Redhat 9

Danny Yoo dyoo@hkn.eecs.berkeley.edu
Mon Jul 28 15:03:13 2003


Hi tpc,



On Fri, 25 Jul 2003 tpc@csua.berkeley.edu wrote:

> hi Danny, here's a head scratcher...  I do what you suggest after I
> installed the mysql-devel via rpm in response to Michael's
> (klappnase@freenet.de) email:

[some content cut]

> So I ran my script again and it gave me the ImportError again.
> However, I got the idea to try python setup.py build and install from
> source and it worked !  The lesson for next time is, if you want to
> upgrade your default MySQL from 3.23 to 4 and you rpm the server and
> client, be sure to also rpm the "Libraries and Header files" portion.

Yes.  The development libraries are pretty necessary for serious work;
I've always been a bit miffed that Red Hat bundles the development headers
separately from the main RPMs, though I understand that they have good
reasons for doing the separation.



> I am not sure why the rpm of MySQL-devel did not work, but it certainly
> allowed the build and install from source to work, which I am grateful
> for.


It actually does make slightly perverse sense.  Here's a summary of what I
think was going on (cc'd to tutor@python.org as a followup):



You had initially had Red Hat's Python installed.  Some time ago, I think
you installed an unofficial RPM of Python 2.3, which overwrote Red Hat's
Python.  (This was sorta bad: it would have been much better to install
Python 2.3 in a separate "local" directory so that it doesn't conflict.
Oh well.)


Later, when you tried installed the MySQL-Python RPM, you ran into
problems.  That's because the MySQL-Python RPM is hardcoded to work with
the Python that's was initially installed with your Red Hat distribution,
not Python 2.3.  Extension modules are version specific, and since you had
installed Python 2.3, the RPM's won't work with it.


So your only recourse is to do it with source.  You tried compiling
MySQL-Python from source, and again ran into problems, but this time, with
compiling the extension module:


> > running build_ext building '_mysql' extension creating
> > build/temp.linux-i686-2.2 gcc -DNDEBUG -O2 -g -pipe -march=i386
> > -mcpu=i686 -D_GNU_SOURCE -fPIC -I/usr/include/mysql
> > -I/usr/local/include/mysql -I/usr/local/mysql/include/mysql
> > -I/usr/include/python2.2 -c _mysql.c -o
> > build/temp.linux-i686-2.2/_mysql.o
>
> > _mysql.c:41:19: mysql.h: No such file or directory


But this too is explainable: compiling anything that deals with MySQL
requires MySQL's development headers, which are included in the
'MySQL-devel' RPM.  As soon as you installed the development package, then
doing:

    python setup.py install

worked.



(Just to clarify: The MySQL-devel RPM not only will allow you to install
Python's MySQLdb module, but drivers for other languages (like Perl's DBI
module) as well.  MySQL-devel consists of a bunch of C header files, so
it's not specifically designed for Python.  You can think of them as the
defined API "interface", and anything that uses that API needs to see that
interface to compile properly.)



Hope this helps elucidate things!  *grin*