升級到OS X EI Caption 10.11.3 後,本地mysql module 導入出錯,以下 html
File "/Library/Python/2.7/site-packages/django/db/utils.py", line 108, in load_backend return import_module('%s.base' % backend_name) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module __import__(name) File "/Library/Python/2.7/site-packages/django/db/backends/mysql/base.py", line 17, in <module> raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e) django.core.exceptions.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
緣由:OS X EI Caption 增長了SIP安全策略,對一些目錄權限進行了調整,或者說是保護 python
解決方案 mysql
1.關閉SIP,風險未知,不過之前版本沒有這個功能,因此也行吧,關閉方法 sql
重啓電腦,開機時按住 cmd + R,進入 Recovery 模式。而後打開終端工具 ,輸入命令:csrutil diable,而後再次重啓電腦便可。 shell
2. 修改動態庫路徑 django
sudo install_name_tool -change libmysqlclient.18.dylib /usr/local/mysql/lib/libmysqlclient.18.dylib /Library/Python/2.7/site-packages/_mysql.so api
參考網上信息,利用/usr/local/ 目錄繞過此問題
安全
參考文章 python2.7