views:

614

answers:

4

I have been trying for the past several hours to find a working method of accessing a mysql database in python. The only thing that I've managed to get to compile and install is pyodbc but the necessary driver is not available for ppc leopard.

I already know about this.

UPDATE:
I've gotten setuptools to install, but now MySQL-python won't build.

UPDATE: Now I've gotten sqlalchemy to install but while it will show up when called by the command line it won't import when used in my cgi script.

+1  A: 

Install fink. It includes the MySQLdb package.

joeforker
I see postgresql in there but not mysql.
GameFreak
I also tried macports but that started installing it's own version of mysql.
GameFreak
Like most package managers, MacPorts is designed to offer a complete solution — not pieces.
Nerdling
If you can't compile pieces of MySQL then let fink, macports etc. compile the whole thing for you. You don't actually have to use the extra bits. The library from that version will probably be able to talk to your database running in a different MySQL.
joeforker
+1  A: 

Try SQL Alchemy.

It is awesome.

Matthew Schinckel
A: 

UPDATE: Now I've gotten sqlalchemy to install but while it will show up when called by the command line it won't import when used in my cgi script.

Can you verify that the Python being invoked from your CGI script is the same as the one you get when you run Python interactively? Check which python and compare it to your webserver CGI settings. That's the only thing I can think of that would cause this - getting it installed in one Python but not the other.

What OS are you on? If you're on something like Ubuntu, sudo apt-get install python-mysqldb is much more reliable than trying to build it yourself.

Also, unless I'm mistaken, SQLAlchemy won't actually help you make the connection itself if you don't have a DB-API2 module (like python-mysqldb) installed - SQLAlchemy sits at the next level up, using the DB-API2 connection and making access to it more Pythonic.

catherine
A: 

I had a lot of problems and have written my solution on my blog. Most of the blog is not programming related but I think this will be of use to you.

Teifion