PyQt5 failed to invoke MySQL interface (qsqldatabase component) How to modify in Linux environment

Source: Internet
Author: User

Recently running under such a code, how to run can not connect to the server, as follows:

#-*-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_ ())

This code no matter how run always can not connect the server-side database, in the Windows platform for a quick day or not, this is to think of using Linux, after all, I still use Linux to get started.

Under the Windows platform can not run, but no error, there is no hint, but in the Linux platform is not the same, there are error messages, as follows:

The error message is as follows:

Qsqldatabase:qmysql Driver not loaded
Qsqldatabase:available drivers:qsqlite qmysql QMYSQL3 qpsql QPSQL7

This hint is still more useful, based on this hint I have a search on the internet, there are really some solutions.

The internet is generally used first to use such a step, as follows:

LDD libqsqlmysql.so (LDD used to print the list of shared libraries on which the program or library file depends)

Then find the file on my computer:

sudo find/-name libqsqlmysql.so

Finally found two places, one in Python below the PYQT5, one is under the/usr/lib, it is obvious that the first file is the file we are looking for.

The LDD command is used to print a list of shared libraries on which a program or library file depends

Then, look for a list of shared libraries for that file, and feel that the problem should be missing on the shared library.

Ldd/usr/local/lib/python3.5/dist-packages/pyqt5/qt/plugins/sqldrivers/libqsqlmysql.so

The output is as follows:

Linux-vdso.so.1 = (0x00007ffc533af000) libqt5sql.so.5 =/usr/local/lib/python3.5/dist-packages/pyqt5/qt/plugins/sqldrivers/. /.. /lib/libqt5sql.so.5 (0x00007faed77c2000) libqt5core.so.5 =/usr/local/lib/python3.5/dist-packages/pyqt5/qt/plugins/sqldrivers/. /.. /lib/libqt5core.so.5 (0x00007faed7072000) libpthread.so.0=/lib/x86_64-linux-gnu/libpthread.so.0 (0x00007faed6e55000) libmysqlclient. So.+ =Not foundLIBSTDC++.so.6 =/usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007faed653f000) libm.so.6 =/lib/x86_64-linux-gnu/libm.so.6 (0x00007faed6236000) libgcc_s.so.1 =/lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007faed6020000) libc.so.6 =/lib/x86_64-linux-gnu/libc.so.6 (0x00007faed5c56000) libz.so.1 =/lib/x86_64-linux-gnu/libz.so.1 (0x00007faed5a3c000) libicui18n.so./usr/local/lib/python3.5/dist-packages/pyqt5/qt/plugins/sqldrivers/. /.. /lib/libicui18n.so.56 (0x00007faed55a3000) libicuuc.so./usr/local/lib/python3.5/dist-packages/pyqt5/qt/plugins/sqldrivers/. /.. /lib/libicuuc.so.56 (0x00007faed51eb000) libicudata.so./usr/local/lib/python3.5/dist-packages/pyqt5/qt/plugins/sqldrivers/. /.. /lib/libicudata.so.56 (0x00007faed3808000) libdl.so.2 =/lib/x86_64-linux-gnu/libdl.so.2 (0x00007faed3604000) Libgthread-2.0.so.0 =/usr/lib/x86_64-linux-gnu/libgthread-2.0.so.0 (0x00007faed3402000) Libglib-2.0.so.0 =/lib/x86_64-linux-gnu/libglib-2.0.so.0 (0x00007faed30f1000)    /lib64/ld-linux-x86-64.so.2 (0x00007faed7c1d000) libssl.so. ten =  not found libcrypto.so. Ten =   not found libpcre.so.3 =/lib/x86_64-linux-gnu/libpcre.so.3 (0x00007faed2e81000)

As you can see, one of the three shared libraries shown above cannot be found.

PyQt5 failed to invoke MySQL interface (qsqldatabase component) How to modify in Linux environment

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.