Windows environment PyQt5 How to install MySQL driver (PyQt5 display driver not loaded solution when connecting to MySQL)

Source: Internet
Author: User

Reference article:

80261695

The previous article said how to install MySQL driver for PyQt5 in Ubuntu environment, which is mainly about how to install MySQL driver in Windows environment.

#-*-coding:utf-8-*-" ""Introduction" Processing database example in PyQt5" "ImportSYS fromPyqt5.qtcoreImport* fromPyqt5.qtguiImport* fromPyqt5.qtwidgetsImport* fromPyqt5.qtsqlImportQsqldatabaseclassExecdatabasedemo (qwidget):def __init__(Self, parent=None): Super (Execdatabasedemo, self).__init__(parent)#self.db = qsqldatabase.adddatabase (' qsqlite ')        #self.db.setDatabaseName ('./db/database.db ')        #Open Database        #Self.db.open ()Self.con2= Qsqldatabase.adddatabase ('Qmysql') Self.con2.setHostName ("67.209.xxx.xxx") Self.con2.setDatabaseName ("MySQL") Self.con2.setUserName ("Root") Self.con2.setPassword ("xxxxxxxx") A=Self.con2.open ()Print(a)defcloseevent (Self, event):#Close the databaseself.con2.close ()if __name__=='__main__': App=qapplication (SYS.ARGV) Demo=Execdatabasedemo () demo.show () Sys.exit (App.exec_ ())

The above is the specific code, after running always print False, which indicates that the database is not connected.

In a Windows environment, the code runs in my programming environment without prompting for any errors, which is different from the Linux environment.

After finding the information on the Internet find the file LibmySQL.dll, this dynamic library can be done, the general installation of MySQL can be found on the computer, the default is generally C:\Program files\mysql\mysql Server 5.6\lib Copy the libmysql.dll file inside

If the Python version is 32-bit, then you have to find the 32-bit Libmysql file.

If the Python version is 64-bit, then you have to find the 64-bit Libmysql file.

One final step:

Put the copy of the libmysql.dll file in the bin directory of the PYQT5/QT, for example, mine is:

C:\Users\devil\AppData\Local\Programs\Python\Python35\Lib\site-packages\PyQt5\Qt\bin

Run the database connection code again, and find that you can connect correctly.

Windows environment PyQt5 How to install MySQL driver (PyQt5 display driver not loaded solution when connecting to MySQL)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.