Pyinstaller生成“RichJupyterWidget with QT4 backend”的可执行文件产生错误

问题描述 投票:1回答:1

以下简单的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
python-2.7 ipython pyqt4 pyinstaller qtconsole
1个回答
0
投票

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

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找到所有这些部分。 :-(

© www.soinside.com 2019 - 2024. All rights reserved.