Python Forum
Error loading MySQLdb module. - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Web Scraping & Web Development (https://python-forum.io/forum-13.html)
+--- Thread: Error loading MySQLdb module. (/thread-13889.html)



Error loading MySQLdb module. - pythonsmurf - Nov-05-2018

Hi all,

Apologies, i am new to python and django, this might be a simple question.

I *had* a perfectly working environment using Django and MySQL 8. The Python components were installed via pip3.

From pip3 freeze:
Django==2.1.3
django-filter==2.0.0
django-formtools==2.1
django-widget-tweaks==1.4.2
mysqlclient==1.3.13
My imac recently updated to Mojave, and the whole thing fell apart and issues connecting to MySQL came up.

this is the output from python3 manage.py makemigrations

[i]
Error:
Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x10e4a92f0> Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/db/backends/mysql/base.py", line 15, in <module> import MySQLdb as Database File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/MySQLdb/__init__.py", line 18, in <module> import _mysql ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/_mysql.cpython-36m-darwin.so, 2): Library not loaded: @rpath/libmysqlclient.21.dylib Referenced from: /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/_mysql.cpython-36m-darwin.so Reason: image not found .... django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module. Did you install mysqlclient?[/i]
So, i have now tried:
Uninstalling and Reinstalling MySQL
Uninstalling and Reinstalling mysqlclient (via pip)
Uninstalling and Reinstalling Django and components (via pip)

i read somewhere that @rpath points to /usr/lib, i have no symbolic link in /usr/lib pointing to /usr/local/mysql/lib where libmysqlclient.21.dylib resides? Maybe thats something to do with it?

No matter what I do, I cant get my environment back up and running again. all the things suggested on google that I have found havent worked.

Has anyone come across this?

Many thanks!


RE: Error loading MySQLdb module. - bishwasbh - Feb-04-2021

This error may pop up due to lack of dependencies and libraries. Follow these steps before pip install mysqlclient.
For Debian / Ubuntu
Quote:sudo apt-get install python3-dev default-libmysqlclient-dev build-essential
sudo apt-get install zlib1g-dev
If this didn't worked try checking this Solution for Django MySQLClient pip compile failure on Linux Arrow Heart