Python MySQLdbLibrary not loaded: /usr/local/mysql/lib/libmysqlclient.20.dylib解决办法

Posted 一切都是最好的安排

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python MySQLdbLibrary not loaded: /usr/local/mysql/lib/libmysqlclient.20.dylib解决办法相关的知识,希望对你有一定的参考价值。

使用MySQLdb遇到以下错误

ImportError: dlopen(/Users/jackey/Documents/Xiaomi/Code/wda_python/lib/python2.7/site-packages/_mysql.so, 2): Library not loaded: /usr/local/mysql/lib/libmysqlclient.20.dylib
  Referenced from: /Users/jackey/Documents/Xiaomi/Code/wda_python/lib/python2.7/site-packages/_mysql.so
  Reason: image not found

原因是_mysql.so找不到

/usr/local/mysql/lib/libmysqlclient.20.dylib

我们看下_mysql.so是怎么找的

(wda_python) bash-3.2$ otool -L /Users/jackey/Documents/Xiaomi/Code/wda_python/lib/python2.7/site-packages/_mysql.so
/Users/jackey/Documents/Xiaomi/Code/wda_python/lib/python2.7/site-packages/_mysql.so:
        /usr/local/mysql/lib/libmysqlclient.20.dylib (compatibility version 20.0.0, current version 20.0.0)
        /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1252.200.5)
(wda_python) bash-3.2$ 

20.dylib是有路径的, 如果这里没有路径需要添加路径, 使用下面用到的修改连接的方法

我们看下/usr/local/mysql/lib目录下面的内容

发现目录中是libmysqlclient.21.dylib

我们修改下_mysql.so的连接到21.dylib

(wda_python) bash-3.2$ sudo install_name_tool -change /usr/local/mysql/lib/libmysqlclient.20.dylib /usr/local/mysql/lib/libmysqlclient.21.dylib /Users/jackey/Documents/Xiaomi/Code/wda_python/lib/python2.7/site-packages/_mysql.so
Password: (wda_python) bash-3.2$

再试下就OK了

 

以上是关于Python MySQLdbLibrary not loaded: /usr/local/mysql/lib/libmysqlclient.20.dylib解决办法的主要内容,如果未能解决你的问题,请参考以下文章

python中的if not

python :print(not ) 》》》 true

python中的if not 怎么用

Python学习--not语句

python is not None

python代码`if not x:` 和`if x is not None:`和`if not x is None:`使用