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

Python flask Reason: image not found libmysqlclient.21.dylib

时间:2019-01-26 17:55:44      阅读:263      评论:0      收藏:0      [点我收藏+]

标签:code   ges   数据库驱动   ade   mysql   root   lib   ica   The   

Python flask Reason: image not found libmysqlclient.21.dylib

折腾了半个下午,在这里找到了答案,在此记录一下,以免后人躺坑

错误提示:

ImportError: dlopen(/Users/XXX/Library/Python/2.7/lib/python/site-packages/_mysql.so, 2): Library not loaded: /usr/local/opt/mysql/lib/libmysqlclient.21.dylib
  Referenced from: /Users/XXX/Library/Python/2.7/lib/python/site-packages/_mysql.so

Reason: image not found

stackoverflow上解释道:

Are you actually using the long-dead connector MySQL-python, aka MySQLdb? If so, that only works with MySQL 5.x (and was only ever fully tested with 5.0).

原来是我的flask用的mysqldb驱动已经太老,已经不能支持最新的Mysql 8,所以这里将数据库驱动换成更新的pymysql(当然如果没有安装要安装一下pip install pymysql

修改config.py

DIALECT = ‘mysql‘
DRIVER = ‘pymysql‘  # 这里改成pymysql驱动
USERNAME = ‘root‘
PASSWORD = ‘root‘
HOST = ‘127.0.0.1‘
PORT = ‘3306‘
DATABASE = ‘xx‘

SQLALCHEMY_DATABASE_URI = "{}+{}://{}:{}@{}:{}/{}?charset=utf8".format(DIALECT, DRIVER, USERNAME, PASSWORD, HOST, PORT, DATABASE)
SQLALCHEMY_TRACK_MODIFICATIONS = False

欸,以后不要稀里糊涂地复制代码了

Python flask Reason: image not found libmysqlclient.21.dylib

标签:code   ges   数据库驱动   ade   mysql   root   lib   ica   The   

原文地址:https://www.cnblogs.com/santiego/p/10324277.html

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