When running python manage.py runserver in Django, you may encounter the following error:
ImproperlyConfigured: Error loading MySQLdb module: dlopen(/Library/Python/2.7/site-packages/_mysql.so, 2): Library not loaded: libmysqlclient.18.dylib Referenced from: /Library/Python/2.7/site-packages/_mysql.so Reason: unsafe use of relative rpath libmysqlclient.18.dylib in /Library/Python/2.7/site-packages/_mysql.so with restricted binary
The Cause
This error occurs due to Apple's implementation of System Integrity Protection in OS X El Capitan (10.11). This prevents programs in protected locations like /usr from accessing shared libraries using relative references.
In this case, the shared library _mysql.so contains a relative reference to libmysqlclient.18.dylib.
The Solution
To resolve this issue, you will need to force _mysql.so to use an absolute reference to libmysqlclient.18.dylib. This can be achieved using the install_name_tool utility.
Steps to Resolve the Issue
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 shared library reference in _mysql.so to use the absolute path to libmysqlclient.18.dylib.
After running this command, you should be able to successfully run python manage.py runserver without the MySQL configuration error.
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3