Library not Loaded: libmysqlclient.18.dylib due to Unsafe Relative Path
Problem Statement:
When running Django's "python manage.py runserver" command, an error occurs due to an unsafe use of a relative path in "_mysql.so" while loading the MySQLdb module. The error reads:
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
Resolution:
This error arises because macOS El Capitan introduces System Integrity Protection, which restricts programs from accessing shared libraries using relative references. "_mysql.so" has a relative reference to "libmysqlclient.18.dylib," but this is now prohibited.
To resolve this, an absolute reference must be forced for "_mysql.so" using the "install_name_tool" utility. Here's how:
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 modifies "_mysql.so" to use the absolute path to "libmysqlclient.18.dylib," thereby resolving the unsafe relative path issue.
The above is the detailed content of How to Resolve \'Library not Loaded: libmysqlclient.18.dylib\' Error in Django on macOS El Capitan?. For more information, please follow other related articles on the PHP Chinese website!