2

我遇到了与帖子类似的问题:

Pyinstaller:ImportError:无法导入名称 QtGui

...但是这篇文章似乎没有解决方案。我不能使用 pyinstaller 来安装非常简单的 PySide 脚本(helloWorld.py):

#!/usr/bin/python
import sys
from PySide import QtGui
from PySide import QtCore
app = QtGui.QApplication(sys.argv)
label = QtGui.QLabel("Hello Plain World")
label.show()
app.exec_()
sys.exit()

我跑:

]$ ./makespec.py -F helloWorld.py
]$ pyinstaller helloWorld.Spec

生成:

fatal: Not a git repository (or any of the parent directories): .git
20 INFO: UPX is not available.
34 INFO: Processing hook hook-os
103 INFO: Processing hook hook-time
104 INFO: Processing hook hook-cPickle
156 INFO: Processing hook hook-_sre
245 INFO: Processing hook hook-cStringIO
308 INFO: Processing hook hook-encodings
316 INFO: Processing hook hook-codecs
599 INFO: Extending PYTHONPATH with /home/derek/BitBucketRepos/tmp/qvt/pyinstaller/tmp
599 INFO: checking Analysis
599 INFO: building Analysis because out00-Analysis.toc non existent
599 INFO: running Analysis out00-Analysis.toc
632 INFO: Analyzing /home/derek/BitBucketRepos/tmp/qvt/pyinstaller/PyInstaller/loader    /_pyi_bootstrap.py
643 INFO: Processing hook hook-os
652 INFO: Processing hook hook-site
661 INFO: Processing hook hook-encodings
726 INFO: Processing hook hook-time
727 INFO: Processing hook hook-cPickle
780 INFO: Processing hook hook-_sre
871 INFO: Processing hook hook-cStringIO
939 INFO: Processing hook hook-codecs
1272 INFO: Processing hook hook-pydoc
1358 INFO: Processing hook hook-email
1398 INFO: Processing hook hook-httplib
1430 INFO: Processing hook hook-email.message
1476 INFO: Analyzing /home/derek/BitBucketRepos/tmp/qvt/pyinstaller/PyInstaller/loader    /pyi_importers.py
1515 INFO: Analyzing /home/derek/BitBucketRepos/tmp/qvt/pyinstaller/PyInstaller/loader    /pyi_archive.py
1542 INFO: Analyzing /home/derek/BitBucketRepos/tmp/qvt/pyinstaller/PyInstaller/loader    /pyi_carchive.py
1570 INFO: Analyzing /home/derek/BitBucketRepos/tmp/qvt/pyinstaller/PyInstaller/loader   /pyi_os_path.py
1573 INFO: Analyzing helloWorld.py
1575 INFO: Processing hook hook-PySide
1575 INFO: Hidden import 'codecs' has been found otherwise
1575 INFO: Hidden import 'encodings' has been found otherwise
1575 INFO: Looking for run-time hooks
objdump: section '.dynamic' mentioned in a -j option, but not found in any input file
2579 INFO: Using Python library /usr/lib/libpython2.7.so.1.0
2579 INFO: Adding Python library to binary dependencies
2964 INFO: Warnings written to /home/derek/BitBucketRepos/tmp/qvt/pyinstaller/tmp/build    /helloWorld/warnhelloWorld.txt
2968 INFO: checking PYZ
2968 INFO: rebuilding out00-PYZ.toc because out00-PYZ.pyz is missing
2968 INFO: building PYZ (ZlibArchive) out00-PYZ.toc
3329 INFO: checking PKG
3329 INFO: rebuilding out00-PKG.toc because out00-PKG.pkg is missing
3329 INFO: building PKG (CArchive) out00-PKG.pkg
objdump: section '.dynamic' mentioned in a -j option, but not found in any input file
10614 INFO: checking EXE
10614 INFO: rebuilding out00-EXE.toc because helloWorld missing
10614 INFO: building EXE from out00-EXE.toc
10614 INFO: Appending archive to EXE /home/derek/BitBucketRepos/tmp/qvt/pyinstaller     /tmp/dist/helloWorld

这成功生成了一个可执行文件,但是当我运行它时,我得到以下输出:

Traceback (most recent call last):
File "<string>", line 4, in <module>
ImportError: cannot import name QtGui

我的系统是 Linux Mint 15 (ubuntu 13.04),安装了 PySide 和 PySide-dev 并使用了很多,我使用的是 pyinstaller 2.0。

任何帮助都会非常有用。

德里克

4

1 回答 1

0

这可能与分析无法检测到的隐藏导入有关。从手册:

如果 Analysis 认为它​​已找到所有导入,但应用程序失败并出现导入错误,则问题是隐藏导入;也就是说,分析阶段不可见的导入。当代码使用import或者可能是 exec 或 eval 时,可能会发生隐藏的导入。您会收到这些警告(请参阅构建时消息)。当扩展模块使用 Python/C API 进行导入时,也会发生隐藏导入。发生这种情况时,Analysis 无法检测到任何东西。不会有任何警告,只会在运行时崩溃。要查找这些隐藏的导入,请设置 -v 标志(上面的获取 Python 的详细导入)。一旦知道它们是什么,就可以使用 --hidden-import= 命令选项、编辑规范文件或使用挂钩文件将所需的模块添加到包中(请参阅下面的使用挂钩文件)。

尝试将以下内容添加到您的规范文件的分析部分:

hiddenimports=['PySide.QtCore','PySide.QtGui']
于 2013-12-31T23:29:09.367 回答