Pyinstaller создал исполняемый файл RichJupyterWidget с бэкэндом QT4, выдает ошибку

Следующий простой код example.py показывает консоль ipython с бэкендом qt4 при запуске.

    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_()

Вывод примера.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.

Пробовал много вещей, которые я мог бы сделать из поиска Google. Кажется, ничего не работает. Любое предложение или помощь высоко ценятся. Спасибо !

Следующая информация может быть полезной

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

person Harsh Kumar Narula    schedule 18.05.2016    source источник
comment
Может быть, заменить from PyQt4.QtGui import * на from PyQt4 import QtGui? В общем, вам следует избегать импорта glob *, не уверен, что это поможет.   -  person Tom Myddeltyn    schedule 19.05.2016
comment
Спасибо, только что попробовал, как вы посоветовали, все равно не работает :(.   -  person Harsh Kumar Narula    schedule 19.05.2016
comment
Вы дочитали здесь? stackoverflow.com/questions/29623543/   -  person Tom Myddeltyn    schedule 19.05.2016
comment
Да, тоже пробовал, год назад работало. С тех пор IPython претерпел несколько изменений, например, IPython.qt устарел. Сейчас это не работает.   -  person Harsh Kumar Narula    schedule 19.05.2016
comment
Наткнулся на интересную тему и вспомнил свое предупреждение. Это дает хороший пример того, почему бы не использовать импорт glob '*': библиотека"> stackoverflow.com/questions/24562216/   -  person Tom Myddeltyn    schedule 23.05.2016


Ответы (1)


У меня такая же проблема. В 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 нашел все эти части. :-(

person OW-52    schedule 14.04.2019