Important: Please read the Qt Code of Conduct -

MainWindow takes 8 seconds to launch, PyQt on OsX

  • I'm used to developing with Qt and PyQt on Linux, but am now creating a hello world on OsX 10.7

    My example, plus all those in the demos folder, take about 8 seconds to launch after run - a rocket icon for Python bounces in the dock for those 8 seconds before the form shows.

    The rocket reports Qt 4.8.2. I am launching example from the terminal. Any tips? This delay is no good for quick development..

  • Where is the slow down; starting python, loading PyQt, or running your application?

    How long does it take to start python from the command prompt?
    If that doesn't take the 8 seconds, then how long does "import PyQt4" or "from PyQt4 import QtGui, QtCore" take?

  • All three of those are imperceptibly quick - milliseconds. I had initially thought it might have been the imports, but it seems to just be a slowdown in bringing up the window, somehow...

  • Do you have an example program?

  • It's happening with any PyQt 4 app, including all the examples..

    The mainwindow launch is just this:

    @def main():
    app = QApplication(sys.argv)
    form = SensorDiagnostics()

    if name == "main":

    Invoking that by:


  • So if you make your form a basic QWidget() does it start faster?

    from PyQt4.QtGui import *

    def main():
    app = QApplication(sys.argv)
    form = QWidget()

    if name == "main":

  • No, just tried it, same delay...

  • Must be some Apple-flavoured magic required. You may need to wait for someone with more OSX/Python/PyQt experience.

  • I'm not that familiar with python, but when you said that the imports are fast, is it possible that they are delayed until you actually use something from the import? So when you imported PyQt4.QtGui but never used anything from there, python just ignored the import?

    //EDIT: another thing. When you write:
    @ app = QApplication(sys.argv)
    form = QWidget()
    app = QApplication(sys.argv)
    form = QWidget()
    does it take 16 seconds?

  • Doesn't seem to take 16 seconds, and I don't think the delayed import thing is it.

    Any other ideas?

  • [quote author="syr123" date="1345443996"]Doesn't seem to take 16 seconds, and I don't think the delayed import thing is it.[/quote]

    But that exactly is the indicator that it probably is the delayed import. If it wasn't, every call of those main functions should take 8 seconds. But as you see, only the first round takes that long, any subsequent ones go faster.

Log in to reply