1

When changing the config to use MySQL as database I'm getting an error trying to start Django server (python manage.py runserver) It is asking me if I installed mysqlclient which I finally was able to do after some digging around on SO. The error it ends with is:

django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module.

High up in the Traceback it states that this exception is causing another exception:

Traceback (most recent call last):
  File "/Users/username/PycharmProjects/projectname/venv/lib/python3.6/site-packages/django/db/backends/mysql/base.py", line 15, in <module>
    import MySQLdb as Database
  File "/Users/username/PycharmProjects/projectname/venv/lib/python3.6/site-packages/MySQLdb/__init__.py", line 18, in <module>
    import _mysql
ImportError: dlopen(/Users/username/PycharmProjects/projectname/venv/lib/python3.6/site-packages/_mysql.cpython-36m-darwin.so, 2): Library not loaded: @rpath/libssl.1.0.0.dylib
  Referenced from: /Users/username/PycharmProjects/projectname/venv/lib/python3.6/site-packages/_mysql.cpython-36m-darwin.so
  Reason: image not found

There are many questions similar to this and I tried quite a bit but can't seem to get this to work. I tried adding MySQLdb as package directly, but then I get the error:

Could not find a version that satisfies the requirement MySQLdb (from versions: ) No matching distribution found for MySQLdb

As said; mysqlclient is installed. Any ideas?

Chrisvdberge
  • 1,824
  • 6
  • 24
  • 46

1 Answers1

2

Finally found this question that included an answer that worked for me. Feels like a workaround and not sure if it has any downsides, but this solved the issue. Copying over the solution for clarity:

pip install pymysql

Then, edit the __init__.py file in your project origin dir(the same as settings.py)

add:

import pymysql

pymysql.install_as_MySQLdb()
Chrisvdberge
  • 1,824
  • 6
  • 24
  • 46