Python PyQt on macOS Sierra

前端 未结 6 1329
忘了有多久
忘了有多久 2020-12-08 15:18

How can I get to work PyQt 4 or 5 on a Mac with OS X Sierra? It seems that I have to wait for a new version of PyQt but I am not sure if that is actually true.

6条回答
  •  执念已碎
    2020-12-08 15:34

    Considering PyQt4 is no longer actively supported by its creators, I'd recommend using PyQt5 (plus I found it much easier to get working). Once you've installed pip3 (you can use easy_install) run the following commands in your terminal:

    1) pip3 install sip
    2) pip3 install PyQt5
    

    You can then run the following sample app to see if everything is working:

    import sys
    from PyQt5 import QtWidgets
    
    def main():
        app = QtWidgets.QApplication(sys.argv)
        window = QtWidgets.QMainWindow()
        button = QtWidgets.QPushButton("Hello, PyQt!")
        window.setCentralWidget(button)
        window.show()
        app.exec_()
    
    if __name__ == '__main__':
        main()
    

提交回复
热议问题