0

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.

Community
  • 1
  • 1
GameFreak
  • 2,881
  • 7
  • 34
  • 38
  • What is wrong about the solution provided in the link? – Paolo Bergantino Mar 07 '09 at 02:13
  • I tried MySQLdb and it won't compile. Also I wanted to avoid it being flagged as a duplicate. – GameFreak Mar 07 '09 at 02:15
  • So the question should be "why won't MySQLdb compile" :p – Paolo Bergantino Mar 07 '09 at 02:36
  • 1
    Indeed. MySQLdb is *the* way to talk to MySQL from Python, and it does run fine on OS X. Google-guessing randomly, maybe this is your problem: http://whereofwecannotspeak.wordpress.com/2007/11/02/mysqldb-python-module-quirk-in-os-x/ – bobince Mar 07 '09 at 02:43
  • I already did that. And after fixing the errors with `uint` I've gotten the error: Traceback (most recent call last): File "setup.py", line 5, in from setuptools import setup, Extension ImportError: No module named setuptools – GameFreak Mar 07 '09 at 02:49
  • Sigh... If all else fails I will just create a PHP bridge, despite the fact that this whole thing is to port a program from PHP to python. – GameFreak Mar 07 '09 at 02:58
  • Then install setuptools, from http://peak.telecommunity.com/DevCenter/setuptools . – Andrew Dalke Mar 07 '09 at 04:07
  • Please update the question with the new facts. – S.Lott Mar 07 '09 at 04:51
  • If sqlalchemy won't import in a CGI script, you might be able to fix it by appending to sys.path at the beginning of your script. – joeforker Mar 15 '09 at 18:21

3 Answers3

2

Try SQL Alchemy.

It is awesome.

Matthew Schinckel
  • 35,041
  • 6
  • 86
  • 121
1

Install fink. It includes the MySQLdb package.

joeforker
  • 40,459
  • 37
  • 151
  • 246
  • I see postgresql in there but not mysql. – GameFreak Mar 07 '09 at 02:39
  • I also tried macports but that started installing it's own version of mysql. – GameFreak Mar 07 '09 at 02:42
  • Like most package managers, MacPorts is designed to offer a complete solution — not pieces. – Jeremy L Mar 07 '09 at 03:14
  • 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 Mar 15 '09 at 18:20
0

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 Devlin
  • 7,383
  • 2
  • 25
  • 17