Home  >  Article  >  Database  >  How to Resolve \'Library not Loaded: libmysqlclient.18.dylib\' Error in Django on macOS El Capitan?

How to Resolve \'Library not Loaded: libmysqlclient.18.dylib\' Error in Django on macOS El Capitan?

Susan Sarandon
Susan SarandonOriginal
2024-10-25 03:44:02602browse

How to Resolve

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:

  1. Ensure that "libmysqlclient.18.dylib" is located in "/usr/local/mysql/lib/".
  2. Run the following command in the Terminal:
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!

Statement:
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