django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module. Did you install mysqlclient?

django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module. Did you install mysqlclient?

After installing django on shared cPanel the following error is recorded in passenger log:

django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module.
Did you install mysqlclient?

The error indicates that the mysqlclient module is missing, but used in the code to connect to the database.

To install mysqlclient module simply enter the virtual environment and run:

pip install mysqlclient

If gcc compiler access is disabled in the WHM you will receive an error:

Unable to execute ‘gcc’: Permission denied

Unable to execute 'gcc': Permission denied
Unable to execute ‘gcc’: Permission denied

so ask your hosting provider to enable compiler access for your cpanel account, or if you are on VPS/Dedicated server and have root-level access, then enable it yourself from WHM > Compiler Access

WHM > Compiler Access
WHM > Compiler Access

afterwards repeat the install command and it should install without errors:

pip install mysqlclient
pip install mysqlclient
whoami
Stefan Pejcic
Join the discussion

I enjoy constructive responses and professional comments to my posts, and invite anyone to comment or link to my site.