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.
免責聲明: 提供的所有資源部分來自互聯網,如果有侵犯您的版權或其他權益,請說明詳細緣由並提供版權或權益證明然後發到郵箱:[email protected] 我們會在第一時間內為您處理。
Copyright© 2022 湘ICP备2022001581号-3