gpt4 book ai didi

pyside - Pyinstaller:ImportError:无法导入名称 QtGui

转载 作者:行者123 更新时间:2023-12-01 05:30:43 26 4
gpt4 key购买 nike

使用最新的 pyinstaller在 Windows 7 上制作独立的 exe (-F),运行 exe 时:

ImportError: cannot import name 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 扩展已成功安装。

最佳答案

解决方法。这有效:

# 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 或 hiddenimports 的许多尝试都失败了。
修改我的环境变量也失败了。
从 .egg 中手动提取各种模块文件有时会奏效。

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

更新:不幸的是,该 exe 仅适用于安装了 Python/Pyside 的机器,不适用于没有 Python 的 XP。

关于pyside - Pyinstaller:ImportError:无法导入名称 QtGui,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11335722/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com