ImportError: dlopen(/Users/quzhen/.conda/envs/supply/lib/python3.6/site-packages/MySQLdb/_mysql.cpyt

问题

ImportError: dlopen(/Users/quzhen/.conda/envs/supply/lib/python3.6/site-packages/MySQLdb/_mysql.cpython-36m-darwin.so, 2): Library not loaded: @rpath/libmysqlclient.21.dylib
  Referenced from: /Users/quzhen/.conda/envs/supply/lib/python3.6/site-packages/MySQLdb/_mysql.cpython-36m-darwin.so
  Reason: image not found

解决

  1. 从mysql安装路径的lib目录下将相应的依赖库建立软链接到/usr/local/lib/下
sudo ln -s /usr/local/mysql/lib/libmysqlclient.21.dylib /usr/lib/libmysqlclient.21.dylib

执行时报错:Operation not permitted
2. 这个只用进入恢复模式(重启时command+R),终端输入csrutil disable,回来就可以了!这样就不会Operation not permitted!
3. 再次执行sudo ln -s /usr/local/mysql/lib/libmysqlclient.21.dylib /usr/lib/libmysqlclient.21.dylib时有报ln: /usr/lib/libmysqlclient.21.dylib: Read-only file system
4. 进入root用户命令行sudo su -,执行:chmod 777 /usr/lib/libmysqlclient.21.dylib

=============================== 还是不行 ====================================
继续
5. 执行命令

sudo install_name_tool -change @rpath/libmysqlclient.21.dylib /usr/local/mysql/lib/libmysqlclient.21.dylib /Users/quzhen/.conda/envs/supply/lib/python3.6/site-packages/MySQLdb/_mysql.cpython-36m-darwin.so

成功解决!!!! 奥利给~~~~
参考链接:待解决:python3安装mysqlclient后,使用时提示“Library not loaded: @rpath/libmysqlclient.21.dylib”
感谢这位救命的兄弟!!!!

你可能感兴趣的:(python,数据库)