数据库
首页 > 数据库> > 【Python MySQLdb】Library not loaded: /usr/local/mysql/lib/libmysqlclient.20.dylib解决办法

【Python MySQLdb】Library 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了

 

标签:libmysqlclient.20,lib,wda,Python,mysql,python,usr,dylib
来源: https://www.cnblogs.com/zhouxihi/p/10688684.html