I installed PyQT5 with pip3 install PyQT5
, and I am trying to run a very basic PyQT5 script:
import sys
from PyQt5.QtWidgets import QApplication, QWidget
class MyWindow(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
self.setGeometry(100, 100, 400, 300)
self.setWindowTitle('Simple PyQt5 Program')
def main():
app = QApplication(sys.argv)
window = MyWindow()
window.show()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
The first few times I run it, it works completely fine. But every so often I run into this error:
qt.qpa.plugin: Could not find the Qt platform plugin "cocoa" in ""
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.
zsh: abort python3 test.py
Reinstalling it as it suggests works temporarily, but then I get the same error after a few runs and it feels very random. So far I have tried setting the QT_QPA_PLATFORM_PLUGIN_PATH environment variable, but this isn’t working. I also have Qt installed through homebrew.