我无法访问 PyQt5 中的 SQL 相关驱动程序。我需要所说的驱动程序来做所有事情。
我用 Anaconda 安装了 PyQt5
我从创建连接的代码开始,检查连接是否有效,为连接创建一个应用
con = QSqlDatabase.addDatabase("QSQLITE")
con.setDatabaseName("solar_system_objects.sqlite")
# Create the application
app = QApplication(sys.argv)
# Try to open the connection, and handle possible errors
if not con.open():
QMessageBox.critical(
None,
"App Name - Error!",
"Database Error: %s" % con.lastError().databaseText(),
)
sys.exit(1)
# Create the application's window
win = QLabel("Connection Successfully Opened!")
win.setWindowTitle("App Name")
win.resize(200, 100)
win.show()
sys.exit(app.exec_())
这给了我错误 Database Error: Driver not loaded
根据我搜索的内容,我尝试使用
检查可用的驱动程序print(list(map(str, QSqlDatabase.drivers())))
它返回一个空列表 [],而不是预期的 PyQt5 附带的六个左右驱动程序的预期列表
我不知道这里出了什么问题。有没有可能我有 PyQt5 的驱动程序没有看到它们?或者我是否可能需要在某个地方获取驱动程序,尤其是 QSQLITE,如果需要,在哪里以及如何获取?