Pyinstaller使用QT4后端生成" RichJupyterWidget的可执行文件"产生错误

时间:2016-05-18 21:27:52

标签: python-2.7 ipython pyqt4 pyinstaller qtconsole

以下简单example.py代码在运行时显示带有qt4后端的ipython控制台。

    import sip
    sip.setapi(u'QDate', 2)
    sip.setapi(u'QDateTime', 2)
    sip.setapi(u'QString', 2)
    sip.setapi(u'QTextStream', 2)
    sip.setapi(u'QTime', 2)
    sip.setapi(u'QUrl', 2)
    sip.setapi(u'QVariant', 2)
    from PyQt4.QtGui import *
    from qtconsole.rich_jupyter_widget import RichJupyterWidget
    from qtconsole.inprocess import QtInProcessKernelManager
    from IPython.lib import guisupport

    class IPythonWidget(RichJupyterWidget):
         def __init__(self, parent=None, **kwargs):
            super(self.__class__, self).__init__(parent)
            self.app = app = guisupport.get_app_qt4()
            self.kernel_manager = kernel_manager = QtInProcessKernelManager()
            kernel_manager.start_kernel()
            self.kernel = kernel = kernel_manager.kernel
            kernel.gui = 'qt4'
            self.kernel_client = kernel_client = kernel_manager.client()
            kernel_client.start_channels()


   if __name__ == '__main__':
        app = QApplication([])
        i = IPythonWidget()
        i.show()
        app.exec_()

Output of example.py

但是,由pyinstaller生成的可执行文件无法运行。 exe文件的调试输出如下:

PyInstaller Bootloader 3.x
LOADER: executable is C:\Users\harshn\Desktop\dist\example\example.exe
LOADER: homepath is C:\Users\harshn\Desktop\dist\example
LOADER: _MEIPASS2 is NULL
LOADER: archivename is C:\Users\harshn\Desktop\dist\example\example.exe
LOADER: No need to extract files to run; setting extractionpath to homepath
LOADER: SetDllDirectory(C:\Users\harshn\Desktop\dist\example)
LOADER: Already in the child - running user's code.
LOADER: Python library: C:\Users\harshn\Desktop\dist\example\python27.dll
LOADER: Loaded functions from Python library.
LOADER: Manipulating environment (sys.path, sys.prefix)
LOADER: sys.prefix is C:\Users\harshn\Desktop\dist\example
LOADER: Setting runtime options
LOADER: Initializing python
LOADER: Overriding Python's sys.path
LOADER: Post-init sys.path is C:\Users\harshn\Desktop\dist\example
LOADER: Setting sys.argv
LOADER: setting sys._MEIPASS
LOADER: importing modules from CArchive
LOADER: extracted struct
LOADER: callfunction returned...
LOADER: extracted pyimod01_os_path
LOADER: callfunction returned...
LOADER: extracted pyimod02_archive
LOADER: callfunction returned...
LOADER: extracted pyimod03_importers
LOADER: callfunction returned...
LOADER: Installing PYZ archive with Python modules.
LOADER: PYZ archive: out00-PYZ.pyz
LOADER: Running pyiboot01_bootstrap.py
LOADER: Running pyi_rth_traitlets.py
LOADER: Running pyi_rth_pkgres.py
LOADER: Running pyi_rth_win32comgenpy.py
LOADER: Running pyi_rth_qt4plugins.py
Qt: Untested Windows version 10.0 detected!
LOADER: Running pyi_rth_mplconfig.py
LOADER: Running pyi_rth_mpldata.py
LOADER: Running pyi_rth__tkinter.py
LOADER: Running example.py
Traceback (most recent call last):
  File "example.py", line 10, in <module>
  File "C:\Users\harshn\Desktop\pyinstallerDev\PyInstaller\loader\pyimod03_importers.py", line 389, in load_module
    exec(bytecode, module.__dict__)
  File "site-packages\qtconsole\rich_jupyter_widget.py", line 9, in <module>
  File "C:\Users\harshn\Desktop\pyinstallerDev\PyInstaller\loader\pyimod03_importers.py", line 389, in load_module
    exec(bytecode, module.__dict__)
  File "site-packages\qtconsole\qt.py", line 23, in <module>
  File "site-packages\qtconsole\qt_loaders.py", line 309, in load_qt
ImportError:
    Could not load requested Qt binding. Please ensure that
    PyQt4 >= 4.7, PyQt5 or PySide >= 1.0.3 is available,
    and only one is imported per session.

    Currently-imported Qt library:   'pyqt'
    PyQt4 installed:                 False
    PyQt5 installed:                 False
    PySide >= 1.0.3 installed:       False
    Tried to load:                   ['pyqt']

Failed to execute script example
LOADER: OK.
LOADER: Cleaning up Python interpreter.

尝试了许多我可能通过谷歌搜索做的事情。似乎没什么用。任何建议或帮助都非常感谢。谢谢!

以下信息可能会有所帮助

Python: 2.7.11 (From Anaconda Python Distribution)
OS: Windows 10 (x64)
PyQt: Version 4.11.4
Pyinstaller Version: 3.2-48-ga00b13d

1 个答案:

答案 0 :(得分:0)

我有同样的问题。在uikit\ipython.py中,我在这里遇到了例外情况。

try:
    from qtconsole.rich_jupyter_widget import RichJupyterWidget
    from qtconsole.inprocess import QtInProcessKernelManager
    print "here 1"

except:
    from IPython.qt.console.rich_ipython_widget import RichIPythonWidget as RichJupyterWidget
    from IPython.qt.inprocess import QtInProcessKernelManager
    print "here 2"

我必须安装qtconsole并解决了。

pip install qtconsole

现在问题出在让pyinstaller查找所有这些部分。 :-(