A Django user has encountered a mysterious error when attempting to run the python manage.py runserver command, receiving the following message:
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 user has installed MySQL-python via Pip and followed a suggested step, but the issue persists. Moreover, they are using the El Capitan Beta 3 operating system.
In OS X El Capitan (10.11), Apple introduced System Integrity Protection (SIP), which restricts programs in protected locations like /usr from accessing shared libraries using relative references. In this case, the _mysql.so shared library includes a relative reference to the shared library libmysqlclient.18.dylib.
While a future update of _mysql.so may resolve this issue, a temporary solution involves forcing the library to use an absolute reference using the install_name_tool utility.
Assuming 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 modify _mysql.so to use the absolute path to the libmysqlclient.18.dylib shared library, resolving the "unsafe use of relative path" error.
The above is the detailed content of Why am I getting an \'unsafe use of relative path\' error with MySQLdb on El Capitan?. For more information, please follow other related articles on the PHP Chinese website!