解决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,不再报错。后尝试连库写表成功

 

上一篇:python-如何扩展peewee以使用逻辑删除?


下一篇:peewee-async集成到tornado