1

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.

9
  • What is wrong about the solution provided in the link? Commented Mar 7, 2009 at 2:13
  • I tried MySQLdb and it won't compile. Also I wanted to avoid it being flagged as a duplicate. Commented Mar 7, 2009 at 2:15
  • So the question should be "why won't MySQLdb compile" :p Commented Mar 7, 2009 at 2: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: whereofwecannotspeak.wordpress.com/2007/11/02/… Commented Mar 7, 2009 at 2: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 <module> from setuptools import setup, Extension ImportError: No module named setuptools Commented Mar 7, 2009 at 2:49

3 Answers 3

2

Try SQL Alchemy.

It is awesome.

Sign up to request clarification or add additional context in comments.

Comments

1

Install fink. It includes the MySQLdb package.

4 Comments

I see postgresql in there but not mysql.
I also tried macports but that started installing it's own version of mysql.
Like most package managers, MacPorts is designed to offer a complete solution — not pieces.
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.
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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.