码迷,mamicode.com
首页 > 数据库 > 详细

【Python MySQLdb】Library not loaded: /usr/local/mysql/lib/libmysqlclient.20.dylib解决办法

时间:2019-04-11 11:56:04      阅读:230      评论:0      收藏:0      [点我收藏+]

标签:src   ges   packages   修改   not   pack   code   site   key   

使用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 MySQLdb】Library not loaded: /usr/local/mysql/lib/libmysqlclient.20.dylib解决办法

标签:src   ges   packages   修改   not   pack   code   site   key   

原文地址:https://www.cnblogs.com/zhouxihi/p/10688684.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!