Python peewee.ImproperlyConfigured : MySQL driver not installed

标签 python mysql-python peewee

我尝试与 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
MySQL 驱动程序。但这完全没有改变。由于我是 python 的新手,我不知道我能做些什么来解决这个问题,如果我只是缺少一个导入或者我是否必须使用 pip 安装一个库?

最佳答案

安装 MySQL 驱动程序:

pip install pymysql

关于Python peewee.ImproperlyConfigured : MySQL driver not installed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62875416/

相关文章:

python - 根据另一个数据框的多列过滤数据框

Python Matplotlib : "ImportError: cannot import name flatten"

python - 无法在 python 中使用带有 gobject-introspection 的库构建

python - 如何在 Union peewee orm 中对 SQL 结果进行排序

python - 如何禁止在实例上调用类方法?

python - 如何在两个列表中找到紧密匹配的唯一元素? (这里使用距离函数)

Python,求和返回的MySQL数据

python - 如何使用 python 克服此 sql 连接错误?

python - 如何使用 MYSQLdb 在 Python 2.7 中正确创建左连接?

python - 使用 Peewee 处理数据库断开连接