Python peewee.ImproperlyConfigured: MySQL driver 未安装

Python peewee.ImproperlyConfigured: MySQL driver not installed

我尝试与 peewee 建立 MySQL 连接,并按照他们网站上的教程进行操作: peewee quickstart

所以我的代码如下:

from peewee import *

db = MySQLDatabase(
    host='127.0.0.1',
    user='root',
    password='',
    database='db_test'
)

class Person(Model):
    name = CharField()
    birthday = DateField()

    class Meta:
        database = db

class Pet(Model):
    owner = ForeignKeyField(Person, backref='pets')
    name = CharField()
    animal_type = CharField()

    class Meta:
        database = db

db.connect()

db.create_tables([Person, Pet])

db.close()

(我的数据库来自 xampp)

但是当我执行此代码时,我收到此错误消息:

peewee.ImproperlyConfigured: MySQL driver not installed!

我试图通过安装来解决这个问题 this MySQLDriver。但这绝对没有改变。由于我是 python 的新手,我不知道我能做些什么来解决这个问题,如果我只是缺少一个导入或者我是否必须使用 pip 安装一个库?

文档很清楚,错误消息也很清楚:http://docs.peewee-orm.com/en/latest/peewee/database.html#using-mysql

安装 pymysql 或 mysqldb.

要使用非标准 mysql-连接器驱动程序,您需要导入 playhouse.mysql_ext 模块并使用 MySQLConnectorDatabase 实现:

http://docs.peewee-orm.com/en/latest/peewee/playhouse.html#mysql-ext

安装 MySQL 驱动程序:

pip install pymysql