views:

72

answers:

2

Installed Django from source (python setup.py install and such), installed MySQLdb from source (python setup.py build, python setup.py install). Using Python 2.4 which came installed on the OS (CentOS 5.5). Getting the following error message after launching the server:

Error loading MySQLdb module: No module named MySQLdb

The pythonpath the debug info provides includes

'/usr/lib/python2.4/site-packages'

and yet, if I ls that directory, I can plainly see

MySQL_python-1.2.3-py2.4-linux-i686.egg

Using the python interactive shell, I can type import MySQLdb and it produces no errors. This leads me to believe it's a Django pathing issue, but I haven't the slightest clue where to start looking as I'm new to both Django and python.

EDIT: And to be a bit more specific, everything is currently running as root. I haven't setup any users yet on the machine, so none exist other than root.

EDITx2: And to be even more specific, web server is Cherokee, and deploying using uWSGI. All installed from source.

A: 

You can find out where Python is looking for it's libraries by invoking "python manage.py shell" from the directory base of your Django project. Then do:

import sys
import pprint
pprint.pprint(sys.path)

And you'll see where the python is pulling libraries from. Also try to do a "import mysql" to see if that's kicking out an error.

Finally, the pathing for the WSGI service is (likely) configured with the uWSGI setup in Cherokee - sorry, I don't know the details of that critter to make suggestions on how to determine where/how it's loading the library path.

heckj
Hmm interesting, running python manage.py shell results in that same error I'm getting.django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named MySQLdb
Whellow
Then it's definitely something in the python pathing. Did looking at the output of pprint.pprint(sys.path) provide any insight into where it's looking (or not) that you expected to include the Egg that you mentioned at the very top?
heckj
Okay, my mistake. I forgot that I had deleted the .egg temporarily while debugging something. I just put it back (reinstalled MySQLdb) and I can run manage.py shell now. The output of pprint showed that it's looking directly at the .egg: /usr/lib/python2.4/site-packages/MySQL_python-1.2.3-py2.4-linux-i686.eggWeird. Anyway, going to the page Cherokee runs still produces the No MySQLdb module error. EDIT: Thanks for your help thus far! Everyone else I've asked so far have been unable to even get this far.
Whellow
I guess the next thing I'd try to do is get the output from sys.path onto an HTML page some how through Cherokee to see what's going on with it's pathing. I would think it has to be different, but I'm getting a bit stuck now without knowing Cherokee.
heckj
Hm, yeah I'm not sure how to get that done either. Will have to dig around Cherokee's documentation or ask them on IRC. Thanks for your help though!
Whellow
+1  A: 

Have you considered installing MySQLdb from python packages? I would also recommend doing this with pip instead of easy_install.

First you can replace easy_install with pip:

easy_install pip
pip install pip --upgrade

And then install Django via PIP:

pip install MySQL-python
pip install Django

Typically easy_install is installed already (part of setuptools), while pip is much better. It avoids offers uninstallation options too, and uses flat install directories instead of the EGG files magic. This might resolve some incompatibilities as well.

vdboor
Trying to run "easy_install install pip" gives me this error: Searching for install |Reading http://pypi.python.org/simple/install/Couldn't find index page for 'install' (maybe misspelled?)
Whellow
@irishb: whoops, my bad. `easy_install` doesn't need a `install` verb first. fixed!
vdboor