解决peewee连接mysql库报ImproperlyConfigured: MySQL driver not installed!的问题

今天用peewee来连接mysql

from peewee import *
#建立连接mysql时的必要参数
db = MySQLDatabase('student',host ='localhost',user='root',passwd='123456')

db.connect

运行后,spyder一直报错


File "C:\ProgramData\Anaconda3\lib\site-packages\peewee.py", line 3981, in _connect
raise ImproperlyConfigured('MySQL driver not installed!')

ImproperlyConfigured: MySQL driver not installed!

开始以为是pymysql没有配好,于是单独测试pymysql,发现能正常运行,

后按报错信息找到peewee.py的3981行,如下:

 if mysql is None:
     raise ImproperlyConfigured('MySQL driver not installed!')

将这两行注释掉,再测试peewee,不再报错。后尝试连库写表成功

 

posted @ 2021-04-10 19:32  ZhongciWang  阅读(1063)  评论(0编辑  收藏  举报