Skip to content Skip to sidebar Skip to footer

Django - Error Loading MySQLdb Module: No Module Named MySQLdb

I'm using Django 1.4.1 with Active Python 2.7 on Win7. I have installed the MySQL module using pypm install mysql-python. The database engine is django.db.backends.mysql. import My

Solution 1:

The problem was that MySQLdb was installed in my home directory C:\Users\alexei\AppData\Roaming\Python\Python27\site-packages\ which was not in Python's path. So I uninstalled it with pypm uninstall mysql-python and then reinstalled it globally using pypm -g install mysql-python (note the -g option).

The alternative is to add that path to the list sys.path.append("...path...") in wsgi.py

So, in case someone else is wondering, you can find out where MySQLdb (or any other module) is installed like so:

import MySQLdb
print MySQLdb.__file__

Make sure that that path is in Python's path list provided in Django's error message.


Solution 2:

If you are using and virtual environment. you must run

cd virtualEnvPath
pip install MySQL-Python

Don't forget positioning inside of your virtual env. /bin PATH, to use local pip. REGARDS!


Solution 3:

i also faced this issue then i installed python mysql to my system

pip install mysql-python

then its workes see this --> working in my system >>
$ python manage.py syncdb;

Creating tables ...
Creating table django_admin_log
Creating table auth_permission
Creating table auth_group_permissions
Creating table auth_group
.............working


Solution 4:

Easiest way is to install MySQLdb from binary: http://www.lfd.uci.edu/~gohlke/pythonlibs/#mysql-python


Solution 5:

I configured djando w/ mysql the following way:

1) set DJANGO_SETTINGS_MODULE environment variable in .bashrc and source it

2) change settings.py pointed by this env_var and local_settings.py (if any) like this (for mysql):

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql', 
        'NAME': 'DB_NAME',
        'USER': 'DB_USER',
        'PASSWORD': 'DB_PASSWORD',
        'HOST': 'localhost',   # Or an IP Address that your DB is hosted on
        'PORT': '3306',
    }
}

3) install mysql dev libraries and header files, ensure that mysql is on PATH

sudo apt-get install libmysqlclient-dev

4) install python package for mysql

sudo pip install MySQL-python

5) test django's access to your mysql db:

python manage.py dbshell

or

django-admin dbshell

6) sync django to mysql from dir with your django app

python manage.py syncdb

Post a Comment for "Django - Error Loading MySQLdb Module: No Module Named MySQLdb"