Home > Database > Mysql Tutorial > body text

Why am I getting an \'unsafe use of relative path\' error with MySQLdb on El Capitan?

Mary-Kate Olsen
Release: 2024-10-24 18:56:30
Original
394 people have browsed it

Why am I getting an

El Capitan User Encounters "unsafe use of relative path" Error with MySQLdb

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
Copy after login

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.

The Culprit: System Integrity Protection

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.

Resolution: Forcing an Absolute Reference

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
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!