无法通过peewee连接到MySQL数据库

问题描述 投票:0回答:1

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

用户具有在数据库模式中创建表的足够权限,因为它可以与pymysql完美配合使用(创建表和模式都可以正常工作)。我在Stackoverflow上看过类似的问题,但找不到类似的问题。而且,在我看过的任何教程中都没有遇到此问题,因此我不确定是导致错误的罪魁祸首。下面是一个最小的工作示例。

    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”中创建一个新表。但是,相反,代码在尝试连接到数据库时会引发错误消息:

/ usr / bin / python3.6:使用/lib/x86_64-linux-gnu/librt.so.1' for IFUNC symbol clock_gettime'重新链接'/lib/x86_64-linux-gnu/libsystemd.so.0'。>

/ usr / bin / python3.6:为IFUNC符号`clock_gettime'重新链接/lib/x86_64-linux-gnu/libudev.so.1' with /lib/x86_64-linux-gnu/librt.so.1'您是否有解决此问题的想法?

提前感谢

[在PyCharm中,我在计算机上使用pymysql创建了一个MySQL模式。现在,我想使用Peewee创建表并编写SQL查询。但是,当...

mysql python-3.6 pymysql peewee
1个回答
0
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.