import MySQLdb出错,Reason: image not found

我是mac,先安装mysql,然后想用python写数据库

我已经安装了anaconda2

我输入

conda install mysql-python

提示找不到源

解决方法:

看:https://blog.csdn.net/qq_28256625/article/details/78893707

然后是下列错误

>>> import MySQLdb
Traceback (most recent call last):
  File "", line 1, in 
  File "/Users/zhangbingwang/anaconda2/lib/python2.7/site-packages/MySQL_python-1.2.5-py2.7-macosx-10.7-x86_64.egg/MySQLdb/__init__.py", line 19, in 
  File "/Users/zhangbingwang/anaconda2/lib/python2.7/site-packages/MySQL_python-1.2.5-py2.7-macosx-10.7-x86_64.egg/_mysql.py", line 7, in 
  File "/Users/zhangbingwang/anaconda2/lib/python2.7/site-packages/MySQL_python-1.2.5-py2.7-macosx-10.7-x86_64.egg/_mysql.py", line 6, in __bootstrap__
ImportError: dlopen(/Users/zhangbingwang/Library/Caches/Python-Eggs/MySQL_python-1.2.5-py2.7-macosx-10.7-x86_64.egg-tmp/_mysql.so, 2): Library not loaded: /usr/local/opt/mysql/lib/libmysqlclient.20.dylib
  Referenced from: /Users/zhangbingwang/Library/Caches/Python-Eggs/MySQL_python-1.2.5-py2.7-macosx-10.7-x86_64.egg-tmp/_mysql.so
  Reason: image not found

发现错误信息是:

Library not loaded: /usr/local/opt/mysql/lib/libmysqlclient.20.dylib

然后我去该路径下查看,发现该位置是

而libmysqlclient.20.dylib在我的/usr/local/mysql/lib/路径下

所以,要设置链接

sudo ln -s /usr/local/mysql/lib/libmysqlclient.20.dylib /usr/local/opt/mysql/lib/libmysqlclient.20.dylib

sudo ln -s /usr/local/mysql/lib /usr/local/opt/mysql/lib/mysql

注意上面的路径和版本信息!

该方法成功解决问题!

 

 

 

 

 

 

 

你可能感兴趣的:(Mac)