MySQLdb Missing Module errors

83 views
Skip to first unread message

Rootz

unread,
Feb 25, 2015, 6:07:47 PM2/25/15
to django...@googlegroups.com
I recently installed the django framework ( v1.7.4 ) and the mysql database connector ( pymysql ) for python. It is my understanding that the MySQLdb python connector is depreciated and is no longer available for download through PIP . However I installed pymysql which is an alternate download for MySQLdb connector for python. The connector (pysql) works with the MySQL database installed but my current django installation does not work because I recieve errors about missing MySQLdb module.

However despite the setback trying to use the MySQLdb package I was able to make changes to the installed django package ( django/db/backends/mysql/base.py ) that
help to make my django projects functional and error free now. 

I hope this will help those in the Django community, whom are affected by the same errors that I was recieving.

Thanks

Below I have outlined some of the changes I made to my django package are as follows:

####Updates made in base.py (The base.py is locate in the django package)
####Path to base.py inside the django package ( django/db/backends/mysql/ )
import pymysql as Database#MySQLdb as Database



from pymysql.converters import conversions, Thing2Literal
from pymysql.constants import FIELD_TYPE, CLIENT


### line 30 - 31 replaced MySQLdb for pymysql
### line 15 replaced MySQLdb for pymysql


#from MySQLdb.converters import conversions, Thing2Literal
#from MySQLdb.constants import FIELD_TYPE, CLIENT




Below is a snippet installing MySQLdb connector using PIP

C:\Users\root\Documents\GitHub\djangoproject-tutorial\tutorial> pip install mysqldb
Downloading/unpacking mySQLdb
 
Could not find any downloads that satisfy the requirement mySQLdb
Cleaning up...
No distributions at all found for mySQLdb
Storing debug log for failure in C:\Users\root\pip\pip.log
C
:\Users\root\Documents\GitHub\djangoproject-tutorial\tutorial>


Below is a snippet of the Django-1.7.4 interacting with the pymysql connector

File "C:\Users\root\Documents\GitHub\djangoproject-tutorial\tutorial\lib\site-packages\django\db\backends\mysql\base.py", line 18, in <module>
   
raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
django
.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named 'MySQLdb'


Tim Graham

unread,
Feb 26, 2015, 7:29:38 AM2/26/15
to django...@googlegroups.com
You're using an incorrect package name for MySQLdb. It should be: pip install MySQL-python
However, we currently recommend using mysqlclient as it's actively maintained.

The officially supported MySQL drivers are documented here:
https://docs.djangoproject.com/en/stable/ref/databases/#mysql-db-api-drivers
Reply all
Reply to author
Forward
0 new messages