Makamu Evans
Makamu Evans

Reputation: 541

Error loading MySQLdb module. Did you install mysqlclient? on MacOS

Am Trying to connect to my mysql db from django app. I get the below error during migration:

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

I've already installed mysqlclient as below:

Requirement already satisfied: mysqlclient in /usr/local/lib/python3.7/site-packages (1.4.2.post1)

I've also tried with pymysql and adding below code to ini.py file:

import pymysql
pymysql.install_as_MySQLdb()

Gives me some other errors. What could be wrong?

Python 3.7 , mysql 5.7 and Django 2.2 are my setup versions.

Upvotes: 3

Views: 8887

Answers (3)

M3RS
M3RS

Reputation: 7530

If the error includes a Reason: image not found error, then it can be solved with symlinks like this:

Library not loaded: @rpath/libmysqlclient.21.dylib Reason: image not found Django migrate error using mysqlclient DB driver and MySQL 8 with macOS

Upvotes: 0

lndh
lndh

Reputation: 1

I had the same issue. The thing that worked for me is the following:

https://stackoverflow.com/a/54521244/12497648,

except when I did brew install mysql-client I got the message Warning: mysql-client 5.7.23_1 is already installed and up-to-date To reinstall 5.7.23_1, run "brew reinstall mysql-client" so I ran brew reinstall mysql-client after which I continued with the instructions from the link above (export PATH... etc.)

(also don't forget to do the pip wheel mysqlclient / pip install mysqlclient)

Upvotes: 0

shawshank718
shawshank718

Reputation: 199

I had the same issue. Running the below command fixed it for me.

pip install --force-reinstall --ignore-installed --no-binary :all: mysqlclient

Upvotes: 17

Related Questions