Traceback (most recent call last):
File “/Volumes/此处省略路径信息.../test.py", line 2, in <module> import MySQLdb as mdb File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/MySQLdb/__init__.py", line 19, in <module> import _mysql ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/_mysql.so, 2): Library not loaded: libmysqlclient.18.dylib Referenced from: /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/_mysql.so Reason: image not found
找不到libmysqlclient.18.dylib这个文件,但这个文件在/usr/local/mysql/lib/下是有的, 只是位置不对,于是我们这样解决.
sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib
ln: /usr/lib/libmysqlclient.18.dylib: Operation not permitted
The computer security settings prevent the shared library _mysql.so from using a relative reference to the library libmysqlclient.18.dylib. In the future, the shared library _mysql.so may be updated. Until then, you can force it to use an absolute reference via the install_name_toolutility. Assuming that libmysqlclient.18.dylib is in /usr/local/mysql/lib/, then run the command
sudo install_name_tool -change libmysqlclient.18.dylib \
/usr/local/mysql/lib/libmysqlclient.18.dylib \
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/_mysql.so
问题解决!
参考: http://errorlog.lofter.com/post/1cb97859_7d3be93
作者: 老毕
微信公众帐号: wirelessqa
博客: http://blog.csdn.net/wirelessqa
微博: http://weibo.com/wirelessqa