Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django unable to find MySQLdb python module

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.

like image 789
Whellow Avatar asked Jul 14 '10 02:07

Whellow


2 Answers

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 offers uninstallation options too, and uses flat install directories instead of the EGG files magic. This might resolve some incompatibilities as well.

like image 172
vdboor Avatar answered Oct 19 '22 19:10

vdboor


Did you try building the dependencies? This solved it for me on Ubuntu:

sudo apt-get build-dep python-mysqldb
pip install MySQLdb-python
like image 34
Honza Pokorny Avatar answered Oct 19 '22 20:10

Honza Pokorny