Django on AWS Elastic Beanstalk - No module named MySQLdb Error

Viewed 1026

I have been using AWS Elastic Beanstalk to run this web app for a while with no issues on Amazon's Linux version Python 2.7 running on 64bit Amazon Linux/2.0.1.

When I tried to "upgrade" to the latest Amazon Linux version: Python 2.7 version, Linux/2.7.7 or any version after 2.0.1, I get this error:

ImproperlyConfigured: Error loading MySQLdb module: No module named MySQLdb.

Did you install mysqlclient or MySQL-python?

I do have both installed and included in my requirements.txt file

MySQL-python==1.2.5
mysqlclient==1.3.14

I tried reinstalling them both and removing them one or the other from the requirements but still no luck.

in my .ebextensions I do have these:

packages:
    yum:
        python27-devel: []
        libmemcached-devel: []
        gcc: []
        libxml2-devel: []
        libxslt-devel: []

I have added the gcc and libx after that so I know they are not causing the error. (I did not try to remove the python27-devel or the libmemcached-devel

Any ideas?

What has changed beyond 2.0.1 since everything is working correctly running version 2.0.1 and it is not working on any newer EB version?

3 Answers

From looking through some past work, I think you may need to add mysql-devel to the yum section in your .ebextensions file

This happened to me as well, from what I can remember is you might need to rebuild the virtual env. In the elastic beanstalk console. Or using the eb command line interface.

Instead install

$ apt-get install python-mysqldb 
Related