1.具体问题描述
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-21-dd22983d5391> in <module>()
----> 1 import MySQLdb
/Users/squirrel/anaconda/lib/python2.7/site-packages/MySQLdb/__init__.py in <module>()
17 from MySQLdb.release import __version__, version_info, __author__
18
---> 19 import _mysql
20
21 if version_info != _mysql.version_info:
ImportError: dlopen(/Users/squirrel/anaconda/lib/python2.7/site-packages/_mysql.so, 2): Library not loaded: libcrypto.1.0.0.dylib
Referenced from: /Users/squirrel/anaconda/lib/python2.7/site-packages/_mysql.so
Reason: image not found
就是 python mysqldb Library not loaded: libssl.1.0.0.dylib
2.解决方案
(1)google到了解决方案:(
https://stackoverflow.com/questi ... ng-once-python-file)
具体如下:
So I discovered I should be working with the libssl.1.0.0.dylib file in /usr/lib, not the file that was mentioned by the error, which was Users/$USERNAME/.python-eggs/MySQL_python-1.2.5-py2.7-macosx-10.5-x86_64.egg-tmp/_mysql.so in my case.
I created a symlink to where libssl.1.0.0.dylib should be referenced from, (/Users/$USERNAME/anaconda/lib/ for me), using
sudo ln -s /Users/$USERNAME/anaconda/lib/libssl.1.0.0.dylib /usr/lib/libssl.1.0.0.dylib
and, once that's done, the same for libcrypto.1.0.0.dylib, as it threw the same error.
sudo ln -s /Users/$USERNAME/anaconda/lib/libcrypto.1.0.0.dylib /usr/lib/libcrypto.1.0.0.dylib
As a side note when listing the files in /usr/bin these two are listed as libss.dylib and libcrypto.dylib.
但是出bug了:
sudo ln -s /Users/squirrel/anaconda/lib/libssl.1.0.0.dylib /usr/lib/libssl.1.0.0.dylib
ln: /usr/lib/libssl.1.0.0.dylib: Operation not permitted
继续google:(
https://stackoverflow.com/questi ... n-rootless-disabled),如下(
就是关闭SIP,也就是rootless特性,比较不安全):
Nvm. For anyone else having this problem you need to reboot your mac and press ⌘+R when booting up. Then go into Utilities > Terminal and type the following commands:
csrutil disablereboot
(3)继续解决
将上面本要链接到/usr/bin
下的改链接到/usr/local/bin
下就好,所以最终的方案如下:
sudo ln -s /Users/squirrel/anaconda/lib/libssl.1.0.0.dylib /usr/local/lib/libssl.1.0.0.dylib
sudo ln -s /Users/squirrel/anaconda/lib/libcrypto.1.0.0.dylib /usr/local/lib/libcrypto.1.0.0.dylib