Pyinstaller: ImportError: cannot import name QtGui

后端 未结 1 1980
你的背包
你的背包 2021-01-03 07:51

Using the latest pyinstaller on Windows 7 to make a standalone exe (-F), when running the exe:

ImportError: cannot import name QtGui

相关标签:
1条回答
  • 2021-01-03 08:27

    Workaround. This worked:

    # Various imports, whatever, using normal sys.path, for example:
    import os, sys, re, time, random
    import subprocess, psutil
    
    # Save sys.path
    sys_path_saved = sys.path
    
    # Limit sys.path for PySide import
    sys.path = ['c:\\python27\\lib\\site-packages']
    
    # PySide imports with limited sys.path
    from PySide        import QtGui, QtCore
    from PySide.QtGui  import QApplication, QLineEdit
    from PySide.QtCore import QSettings, Qt
    
    # Reset sys.path to original
    sys.path = sys_path_saved
    
    # Remainder of code...
    

    Pyinstaller 1.5.1 should do a fine job of locating dependencies, and often does. However, all of many many attempts to use its pathex or hiddenimports in .spec failed. Modifying my environment variables also failed. Extracting various module files manually from from .egg sometimes worked.

    However for PySide imports, the sys.path temporary limitation above was the workaround that worked.

    Update: Unfortunately the exe only works on a machine with Python/Pyside installed, doesn't work on XP without Python.

    0 讨论(0)
提交回复
热议问题