「Python」使用flask_sqlalchemy连接数据库获取数据时以下错误

错误:

builtins.ImportError
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/_mysql.cpython-37m-darwin.so, 2): Library not loaded: @rpath/libmysqlclient.21.dylib
  Referenced from: /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/_mysql.cpython-37m-darwin.so
  Reason: image not found

image.png

解决办法:
sudo install_name_tool -change @rpath/libmysqlclient.21.dylib /usr/local/mysql/lib/libmysqlclient.21.dylib /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/_mysql.cpython-37m-darwin.so

前半部分路径基本一样
后半部分路径因人而异

你可能感兴趣的:(「Python」使用flask_sqlalchemy连接数据库获取数据时以下错误)