I'm starting down the path of learning Python/Django and have hit my first snag. When attempting to set my database in settings.py
, the internal server fails with:
File "/Library/Python/2.7/site-packages/django/db/backends/mysql/base.py", line 16, in <module>
raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: dlopen(/Users/rob/.python-eggs/MySQL_python-1.2.3-py2.7-macosx-10.7-intel.egg-tmp/_mysql.so, 2): Library not loaded: libmysqlclient.18.dylib
Referenced from: /Users/rob/.python-eggs/MySQL_python-1.2.3-py2.7-macosx-10.7-intel.egg-tmp/_mysql.so
Reason: image not found
There are a lot of solutions that I've found, mostly involving the explicit definition of my DYLD_LIBRARY_PATH
value, but that doesn't work for me. MysQL-Python
is installed (v1.2.3).
Any idea what I might need to do to push through this?
Thanks.
UPDATE
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'django_tutorial', # Or path to database file if using sqlite3.
'USER': 'root', # Not used with sqlite3.
'PASSWORD': '', # Not used with sqlite3.
'HOST': '', # Set to empty string for localhost. Not used with sqlite3.
'PORT': '', # Set to empty string for default. Not used with sqlite3.
}
}
From your comments, it appears that the libmysqlclient
dylib was installed with a non-absolute library name path. That's contrary to standard practice on OS X which is different from most other Unix-y systems in this respect. You should be able to permanently fix the problem (at least until your next upgrade) by modifying the path in the .so file by using install_name_tool
or you can make it work by ensuring your Django instance is running with the following environment variable defined:
export DYLD_LIBRARY_PATH=/usr/local/mysql/lib
You also might be able to get it to work by creating a symlink in /usr/local/lib
to the dylib in /usr/local/mysql/lib
since /usr/local/lib
is on the default dynamic load search path, so (untested!) something like:
sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/local/lib/libmysqlclient.18.dylib
A better long-term solution is to not use a broken MySQL client installation as suggested in Python import MySQLdb error - Mac 10.6.
Using a homebrew installation of mysql
, this worked for me:
$ mdfind libmysqlclient
/usr/local/Cellar/mysql/5.7.9/lib/libmysqlclient.20.dylib
/usr/local/Cellar/mysql/5.7.9/lib/libmysqlclient.a
/usr/local/Cellar/mysql/5.6.27/lib/libmysqlclient.18.dylib
/usr/local/Cellar/mysql/5.6.27/lib/libmysqlclient.a
/usr/local/Cellar/mysql/5.6.26/lib/libmysqlclient.18.dylib
/usr/local/Cellar/mysql/5.6.26/lib/libmysqlclient.a
$ sudo ln -s /usr/local/Cellar/mysql/5.6.27/lib/libmysqlclient.18.dylib /usr/local/lib/libmysqlclient.18.dylib
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With