ImportError: No module name MySQLdb

Fred fredg at fastmail.fm
Wed Jan 25 20:41:27 EST 2006


I hope someone can help me with the below problem...

Thanks,
Fred

My enviroment:
--------------------------
Slackware Linux 10.2
Python 2.4.2
MySql version 4.1.14
MySql-Python 1.2.0

What I am trying to do:
---------------------------
Using MySQL, Python, My-Sql-Python module and CGI create a simple
database that can be accesed with a webpage.

Everything worked great up to this error when trying to load the
webpage:
"ImportError: No module name MySQLdb"

Note that I do NOT get the error when running the script normally from
Python.

I have read much but can not seem to nail the problem down, I am
thinking a path error.

This script works perfect when launched from the command line:
--------------------------------------------------------------
#!/usr/bin/python
import MySQLdb
import cgi
host = '192.168.0.112'
db = 'phone'

db=MySQLdb.connect(host = '192.168.0.112', db = 'phone')
cursor=db.cursor()
cursor.execute("Select * from phone")
result = cursor.fetchall()
for record in result:
  print record[0],record[1],record[2]


I created a webpage with this code:
------------------------------------
<html>
<form action="cgi-bin/mysqld_script_test.py">
<input type="submit">
</form>
</html>
------------------------------------

The webpage "submit" button loads the below script:
If I try the below I get the "ImportError: No module name MySQLdb"
in my Apache error log file
---------------------------------------------------------------------------------
#mysqld_script_test.py
#!/usr/bin/python

import MySQLdb
import cgi
print "Content-Type: text/html\n"

host = '192.168.0.112'
db = 'phone'

db=MySQLdb.connect(host = '192.168.0.112', db = 'phone')
cursor=db.cursor()
cursor.execute("Select * from phone")
result = cursor.fetchall()
for record in result:
  print record[0],record[1],record[2]




More information about the Python-list mailing list