Qt/PyQt cannot connect to the database problem solution
Preface
First run the following two lines of code, if it is consistent with the following, you can adopt the solution
from PyQt5.QtSql import QSqlDatabase
print(QSqlDatabase.drivers())
If 'QMYSQL' and 'QMYSQL3' are missing as shown in the figure below, it means these two drivers are missing in the system. Use the following method to solve the problem.
solution
Move the two files libmysql.dll and qsqlmysql.dll to the path where the red box is located. Everyone's path is different and the approximate path is as follows (find plugins\sqldrivers according to your own situation):
正常python:python\Lib\site-packages\PyQt5\Qt5\plugins\sqldrivers
Anaconda:Anaconda\Lib\site-packages\PyQt5\Qt5\plugins\sqldrivers
QT:Qt5.12\5.12\msvc\plugins\sqldrivers
CSDN download point [ here ] Baidu cloud download point [ here ] extraction code 2333, if possible, use CSDN download to support it.
some mistakes
If the error
"Cannot mix incompatible Qt library (XXX) with this library (XXX)" is reported
, it is a version mismatch problem.
Run the following two lines of code to downgrade the version to pyqt5.12.1
pip uninstall pyqt
pip install pyqt == 5.12.1
#下面这两行不一定要运行
#pip uninstall pyqt-tools
#pip install pyqt-tools