无法使用 peewee 连接到 MySQL 数据库

Unable to connect to a MySQL DB with peewee

在 PyCharm 中,我在计算机上使用 pymysql 创建了一个 MySQL 模式。现在我想使用 Peewee 创建 tables 并编写 SQL 查询。但是,我在尝试连接到数据库时总是收到一条错误消息(见下文)。

用户有足够的权限在数据库模式中创建 tables,因为它可以完美地与 pymysql 一起工作(创建 tables 以及模式工作正常)。 我在 Whosebug 上查看了类似的问题,但找不到类似的问题。此外,在我看过的任何教程中都没有遇到过这个问题,所以我不完全确定导致错误的罪魁祸首是什么。下面是一个最小的工作示例。

    from peewee import*
    import peewee

    user = 'root'
    password = 'root'
    db_name = 'peewee_demo'

    # The schema with the name 'peewee_demo' exists
    db = MySQLDatabase(db_name, user=user, passwd=password)


    class Book(peewee.Model):
        author = peewee.CharField()
        title = peewee.TextField()

        class Meta:
            database = db


    db.connect()  # Code fails here
    Book.create_table()
    book = Book(author="me", title='Peewee is cool')
    book.save()
    for book in Book.filter(author="me"):
        print(book.title)

我希望上面的代码连接到 MySQL,然后在模式“peewee_demo”中创建一个新的 table。但是,代码在尝试连接到数据库时会抛出一条错误消息:

/usr/bin/python3.6: Relink '/lib/x86_64-linux-gnu/libsystemd.so.0' with /lib/x86_64-linux-gnu/librt.so.1' for IFUNC symbol clock_gettime'

/usr/bin/python3.6: Relink /lib/x86_64-linux-gnu/libudev.so.1' with /lib/x86_64-linux-gnu/librt.so.1' for IFUNC symbol `clock_gettime' Do you have any ideas how to fix this issue?

提前致谢

正如@coleifer 在他的评论中指出的那样,该错误可能与 Python 中的共享库问题有关。设置新的虚拟环境并安装所有必需的软件包后,一切运行良好。

我刚刚添加了答案以便能够关闭问题。如果@coleifer 将他的评论转换为答案,我将删除我的并接受他的评论。