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

**URL:** <https://forum.djangoproject.com/t/django-core-exceptions-improperlyconfigured-error-loading-mysqldb-module-did-you-install-mysqlclient/39803>\
**Category:** Mystery Errors\
**Created:** [March 23, 2025, 11:21am UTC](https://forum.djangoproject.com/t/django-core-exceptions-improperlyconfigured-error-loading-mysqldb-module-did-you-install-mysqlclient/39803 "2025-03-23T11:21:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sagar1343](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/sagar1343/32/27680_2.png) [@sagar1343](https://forum.djangoproject.com/u/sagar1343)\
**Post date:** [March 23, 2025, 11:21am UTC](https://forum.djangoproject.com/t/django-core-exceptions-improperlyconfigured-error-loading-mysqldb-module-did-you-install-mysqlclient/39803/1 "2025-03-23T11:21:44Z")

</div>

❯ python3 manage.py runserver  
Watching for file changes with StatReloader  
Exception in thread django-main-thread:  
Traceback (most recent call last):  
File “/Users/sagar/Development/private\_share\_backend/.venv/lib/python3.12/site-packages/django/db/backends/mysql/base.py”, line 16, in   
import MySQLdb as Database  
File “/Users/sagar/Development/private\_share\_backend/.venv/lib/python3.12/site-packages/MySQLdb/ **init**.py”, line 17, in   
from . import \_mysql  
ImportError: dlopen(/Users/sagar/Development/private\_share\_backend/.venv/lib/python3.12/site-packages/MySQLdb/\_mysql.cpython-312-darwin.so, 0x0002): symbol not found in flat namespace ‘\_mysql\_affected\_rows’

The above exception was the direct cause of the following exception:

Traceback (most recent call last):  
File “/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/threading.py”, line 1073, in \_bootstrap\_inner  
self.run()  
File “/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/threading.py”, line 1010, in run  
self.\_target(\*self.\_args, \*\*self.\_kwargs)  
File “/Users/sagar/Development/private\_share\_backend/.venv/lib/python3.12/site-packages/django/utils/autoreload.py”, line 64, in wrapper  
fn(\*args, \*\*kwargs)  
File “/Users/sagar/Development/private\_share\_backend/.venv/lib/python3.12/site-packages/django/core/management/commands/runserver.py”, line 126, in inner\_run  
autoreload.raise\_last\_exception()  
File “/Users/sagar/Development/private\_share\_backend/.venv/lib/python3.12/site-packages/django/utils/autoreload.py”, line 87, in raise\_last\_exception  
raise \_exception[1]  
File “/Users/sagar/Development/private\_share\_backend/.venv/lib/python3.12/site-packages/django/core/management/ **init**.py”, line 394, in execute  
autoreload.check\_errors(django.setup)()  
File “/Users/sagar/Development/private\_share\_backend/.venv/lib/python3.12/site-packages/django/utils/autoreload.py”, line 64, in wrapper  
fn(\*args, \*\*kwargs)  
File “/Users/sagar/Development/private\_share\_backend/.venv/lib/python3.12/site-packages/django/ **init**.py”, line 24, in setup  
apps.populate(settings.INSTALLED\_APPS)  
File “/Users/sagar/Development/private\_share\_backend/.venv/lib/python3.12/site-packages/django/apps/registry.py”, line 116, in populate  
app\_config.import\_models()  
File “/Users/sagar/Development/private\_share\_backend/.venv/lib/python3.12/site-packages/django/apps/config.py”, line 269, in import\_models  
self.models\_module = import\_module(models\_module\_name)  
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  
File “/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/importlib/ **init**.py”, line 90, in import\_module  
return \_bootstrap.\_gcd\_import(name[level:], package, level)  
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  
File “”, line 1387, in \_gcd\_import  
File “”, line 1360, in \_find\_and\_load  
File “”, line 1331, in \_find\_and\_load\_unlocked  
File “”, line 935, in \_load\_unlocked  
File “”, line 995, in exec\_module  
File “”, line 488, in \_call\_with\_frames\_removed  
File “/Users/sagar/Development/private\_share\_backend/.venv/lib/python3.12/site-packages/django/contrib/auth/models.py”, line 5, in   
from django.contrib.auth.base\_user import AbstractBaseUser, BaseUserManager  
File “/Users/sagar/Development/private\_share\_backend/.venv/lib/python3.12/site-packages/django/contrib/auth/base\_user.py”, line 40, in   
class AbstractBaseUser(models.Model):  
File “/Users/sagar/Development/private\_share\_backend/.venv/lib/python3.12/site-packages/django/db/models/base.py”, line 143, in **new**  
new\_class.add\_to\_class(“\_meta”, Options(meta, app\_label))  
File “/Users/sagar/Development/private\_share\_backend/.venv/lib/python3.12/site-packages/django/db/models/base.py”, line 371, in add\_to\_class  
value.contribute\_to\_class(cls, name)  
File “/Users/sagar/Development/private\_share\_backend/.venv/lib/python3.12/site-packages/django/db/models/options.py”, line 231, in contribute\_to\_class  
self.db\_table, connection.ops.max\_name\_length()  
^^^^^^^^^^^^^^  
File “/Users/sagar/Development/private\_share\_backend/.venv/lib/python3.12/site-packages/django/utils/connection.py”, line 15, in **getattr**  
return getattr(self.\_connections[self.\_alias], item)  
~~~~~~~~~~~~~~~~~ ^^^^^^^^^^^^^  
File “/Users/sagar/Development/private\_share\_backend/.venv/lib/python3.12/site-packages/django/utils/connection.py”, line 62, in **getitem**  
conn = self.create\_connection(alias)  
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  
File “/Users/sagar/Development/private\_share\_backend/.venv/lib/python3.12/site-packages/django/db/utils.py”, line 193, in create\_connection  
backend = load\_backend(db[“ENGINE”])  
^^^^^^^^^^^^^^^^^^^^^^^^^^  
File “/Users/sagar/Development/private\_share\_backend/.venv/lib/python3.12/site-packages/django/db/utils.py”, line 113, in load\_backend  
return import\_module(“%s.base” % backend\_name)  
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  
File “/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/importlib/ **init**.py”, line 90, in import\_module  
return \_bootstrap.\_gcd\_import(name[level:], package, level)  
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  
File “/Users/sagar/Development/private\_share\_backend/.venv/lib/python3.12/site-packages/django/db/backends/mysql/base.py”, line 18, in   
raise ImproperlyConfigured(  
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module.  
Did you install mysqlclient?

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [March 23, 2025, 11:49am UTC](https://forum.djangoproject.com/t/django-core-exceptions-improperlyconfigured-error-loading-mysqldb-module-did-you-install-mysqlclient/39803/2 "2025-03-23T11:49:40Z")

</div>

Welcome @sagar1343 !

This error message seems quite straight forward, both the cause and the answer.

Do you have a question here?

---

<div class="post-metadata">

**Author:** ![sagar1343](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/sagar1343/32/27680_2.png) [@sagar1343](https://forum.djangoproject.com/u/sagar1343)\
**Post date:** [March 23, 2025, 12:00pm UTC](https://forum.djangoproject.com/t/django-core-exceptions-improperlyconfigured-error-loading-mysqldb-module-did-you-install-mysqlclient/39803/3 "2025-03-23T12:00:13Z")

</div>

Hi @KenWhitesell ,

I’m having trouble installing mysqlclient on my macOS machine. Despite reinstalling MySQL, the error persists. I’ve tried several troubleshooting steps without success. Here’s what I’ve done so far:

1. Installed MySQL using Homebrew.

2. Installed mysql-client using Homebrew and exported the necessary paths.

3. Navigated to my project directory and ran pipenv install mysqlclient. While it installed successfully, the same error continues to appear.

---

<div class="post-metadata">

**Author:** ![medmunds](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/medmunds/32/22140_2.png) [@medmunds](https://forum.djangoproject.com/u/medmunds)\
**Post date:** [March 26, 2025, 7:08pm UTC](https://forum.djangoproject.com/t/django-core-exceptions-improperlyconfigured-error-loading-mysqldb-module-did-you-install-mysqlclient/39803/4 "2025-03-26T19:08:39Z")

</div>

> [@sagar1343](#):
>
> django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module.  
> Did you install mysqlclient?

I run into this error pretty regularly on macOS after upgrading (or downgrading) MySQL using homebrew. The error message is confusing, because I _have_ installed the mysqlclient Python package—it’s just failing to load properly.

The problem is your pip cache has a mysqlclient built with the wrong MySQL version, and pip keeps reinstalling that.

To fix, force pip to rebuild it ignoring the cache:

```shell
pip install --force --no-cache mysqlclient==<version>

```
