Montag, 26. August 2013

PyQt 5, Spyder and the input hook.

As mentioned in the last post, the input hook of Spyder is actually necessary to interactively edit your application while running. So how to make Spyder install its hook to PyQt 5 instead of its own PyQt 4?
The solution is a bit hacky but quite simple: Go to your Python folder, like
 C:\Python33\Lib\site-packages\spyderlib\widgets\externalshell
there is file sitecustomize.py waiting for you. For safety make copy of that file as we are going to change it a little bit.
Now open it and find the lines (should be 247 to 249):
    if os.environ.get("INSTALL_QT_INPUTHOOK", "").lower() == "true":
        if os.environ["QT_API"] == 'pyqt':
            from PyQt4 import QtCore
And change the last  from
from PyQt4 import QtCore
to
from PyQt5 import QtCore
Now Spyder imports the QtCore module from PyQt 5 instead of PyQt 4. The hook is beeing installed on the first loading of QtCore, so when Sypder launches its consoles now, everything is fine.

Happy playing!


Keine Kommentare: