How to fix this error: the PyQt5.QtCore module failed to register with the sip module

1.9k Views Asked by At

I am trying to use the API of my investment company(kiwoom). There is an instruction on how to use API so I was just replicating it. But the following codes keep giving me an error message that:

the PyQt5.QtCore module failed to register with the sip module

I looked it up and it seems to have to do with the compatibility of the versions of sip and pyqt5. In case you need, my SIP version is 4.19.19 and PyQt version is 5.9.2. But this is just my guess. Any help would be appreciated.

import sys
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QAxContainer import *

class MyWindow(QMainWindow):
    def __init__(self):
        super().__init__()
        self.setWindowTitle("PyStock")
        self.setGeometry(300, 300, 300, 150)

        self.kiwoom = QAxWidget("KHOPENAPI.KHOpenAPICtrl.1")

        btn1 = QPushButton("Login", self)
        btn1.move(20, 20)
        btn1.clicked.connect(self.btn1_clicked)

        btn2 = QPushButton("Check state", self)
        btn2.move(20, 70)
        btn2.clicked.connect(self.btn2_clicked)

    def btn1_clicked(self):
        ret = self.kiwoom.dynamicCall("CommConnect()")

    def btn2_clicked(self):
        if self.kiwoom.dynamicCall("GetConnectState()") == 0:
            self.statusBar().showMessage("Not connected")
        else:
            self.statusBar().showMessage("Connected")

if __name__ == "__main__":
    app = QApplication(sys.argv)
    myWindow = MyWindow()
    myWindow.show()
    app.exec_()
0

There are 0 best solutions below