Pyside Pyinstaller:ImportError:无法导入名称QtGui

Pyside Pyinstaller:ImportError:无法导入名称QtGui,pyside,pyinstaller,Pyside,Pyinstaller,运行exe时,使用Windows 7上的最新版本生成独立exe(-F): ImportError:无法导入名称QtGui 在pyinstaller hooks目录中,虽然不是PySide,但对PyQt4有特殊处理 希望能找到一个解决办法,或者尝试一下 环境 Windows 7 64位 Python 2.7 32位 PYTHONHOME=c:\python27 PYTHONPATH=c:\python27\lib PYTHONLIB=c:\python27\libs\python27.lib;c:

运行exe时,使用Windows 7上的最新版本生成独立exe(-F):

ImportError:无法导入名称QtGui

在pyinstaller hooks目录中,虽然不是PySide,但对PyQt4有特殊处理

希望能找到一个解决办法,或者尝试一下

环境
Windows 7 64位
Python 2.7 32位
PYTHONHOME=c:\python27
PYTHONPATH=c:\python27\lib
PYTHONLIB=c:\python27\libs\python27.lib;c:\python27\lib\site包

步骤
1.从
2.解压缩到c:\pyinstaller1.5.1
3.对仅包含以下内容的.py文件运行以下命令:

from PySide import QtGui
[…或QtCore或]

跑步

c:\pyinstaller1.5.1>pyinstaller.py -F import_test.py
108 INFO: wrote c:\pyinstaller1.5.1\import_test.spec
171 INFO: Testing for ability to set icons, version resources...
296 INFO: ... resource update available
312 INFO: UPX is not available.
4321 INFO: checking Analysis
4382 INFO: checking PYZ
4430 INFO: checking PKG
4446 INFO: building because c:\pyinstaller1.5.1\build\pyi.win32\import_test\import_test.exe.manifest changed
4446 INFO: building PKG out00-PKG.pkg
16782 INFO: checking EXE
16782 INFO: rebuilding out00-EXE.toc because pkg is more recent
16782 INFO: building EXE from out00-EXE.toc
16799 INFO: Appending archive to EXE c:\pyinstaller1.5.1\dist\import_test.exe

c:\pyinstaller1.5.1>dist\import_test.exe
Traceback (most recent call last):
  File "<string>", line 23, in <module>
ImportError: cannot import name QtGui
c:\pyinstaller1.5.1>pyinstaller.py-F import\u test.py
108信息:编写了c:\pyinstaller1.5.1\import\u test.spec
171信息:测试设置图标、版本资源的能力。。。
296信息:。。。资源更新可用
312信息:UPX不可用。
4321信息:检查分析
4382信息:正在检查PYZ
4430信息:检查包装
4446信息:由于c:\pyinstaller1.5.1\build\pyi.win32\import\u test\import\u test.exe.manifest已更改而生成
4446信息:建筑包装out00-PKG.PKG
16782信息:正在检查EXE
16782信息:正在重建out00-EXE.toc,因为pkg是最新的
16782信息:从out00-EXE.toc生成EXE
16799信息:将存档附加到EXE c:\pyinstaller1.5.1\dist\import\u test.EXE
c:\pyinstaller1.5.1>dist\import\u test.exe
回溯(最近一次呼叫最后一次):
文件“”,第23行,在
ImportError:无法导入名称QtGui
注意 At the end of the PySide install (as admin), this message: close failed in file object destructor: sys.excepthook is missing lost sys.stderr If that is about post install it can be handled manually: c:>python.exe c:\Python27\Scripts\pyside_postinstall.py -install Generating file C:\python27\qt.conf... PySide installed in c:/python27/Lib/site-packages/PySide... The PySide extensions were successfully installed. PySide安装(以管理员身份)结束时,此消息: 在文件对象析构函数中关闭失败: sys.excepthook丢失 丢失的系统标准 如果是关于安装后的问题,可以手动处理: c:>python.exe c:\Python27\Scripts\pyside\u postinstall.py-安装 正在生成文件C:\python27\qt.conf。。。 PySide安装在c:/python27/Lib/site-packages/PySide。。。 PySide扩展已成功安装。
解决方法。这起到了作用:

# 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应该能够很好地定位依赖项,而且经常这样做。 但是,在.spec中多次尝试使用其pathex或HiddeImports都失败了。 修改我的环境变量也失败了。 从.egg手动提取各种模块文件有时是有效的

但是,对于PySide导入,上面的sys.path临时限制是有效的解决方法


更新:不幸的是,exe只能在安装了Python/Pyside的机器上工作,在没有Python的XP上无法工作。

对我来说,直接起作用的是从我的Python安装文件夹(Python_文件夹/Lib/site包)复制/粘贴两个文件夹
PySide6
shiboken6
pyinstaller SCRIPT\u NAME
生成的dist/APP\u NAME文件夹