在 Windows 7 上使用最新的pyinstaller制作独立的 exe (-F),运行 exe 时:
ImportError:无法导入名称 QtGui
在 pyinstaller hooks 目录中,PyQt4 有特殊处理,但 PySide 没有。
希望对此有解决方法或尝试一些方法。
环境
Windows 7 64 位
Python 2.7 32 位
PYTHONHOME=c:\python27
PYTHONPATH=c:\python27\lib
PYTHONLIB=c:\python27\libs\python27.lib;c:\python27\lib\site-packages
步骤1. 从http://releases.qt-project.org/pyside/1.1.1/PySide-1.1.1qt474.win32-py2.7.exe
添加 PySide
2. 解压https://github.com/pyinstaller/ pyinstaller/zipball/develop到 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
笔记
在 PySide 安装结束时(以管理员身份),此消息: 在文件对象析构函数中关闭失败: sys.excepthook 丢失 丢失 sys.stderr 如果这是关于安装后的,可以手动处理: c:>python.exe c:\Python27\Scripts\pyside_postinstall.py -install 正在生成文件 C:\python27\qt.conf... PySide 安装在 c:/python27/Lib/site-packages/PySide... PySide 扩展已成功安装。