MySQL Improperly Configured: Resolving Relative Path Error
When encountering the "ImproperlyConfigured: Error loading MySQLdb module" error in Django, it indicates an improper configuration related to the path to the MySQL client library. Here's a breakdown of the issue and a solution for OS X El Capitan users:
Issue:
In OS X El Capitan (10.11), Apple implemented System Integrity Protection (SIP), which prevents programs in protected locations from using libraries referenced with relative paths. The MySQL-Python module references the shared library "libmysqlclient.18.dylib" using a relative path in "/Library/Python/2.7/site-packages/_mysql.so".
Solution:
To resolve this issue, you can force _mysql.so to use an absolute reference to "libmysqlclient.18.dylib" using the "install_name_tool" utility. Assuming that "libmysqlclient.18.dylib" is located in "/usr/local/mysql/lib/", execute the following command:
sudo install_name_tool -change libmysqlclient.18.dylib \ /usr/local/mysql/lib/libmysqlclient.18.dylib \ /Library/Python/2.7/site-packages/_mysql.so
This command will update the reference in "_mysql.so" to the absolute path of "libmysqlclient.18.dylib", allowing Django to successfully load the MySQL client library.
The above is the detailed content of Why Does Django Throw \'ImproperlyConfigured: Error Loading MySQLdb Module\' on OS X El Capitan?. For more information, please follow other related articles on the PHP Chinese website!