我在尝试使用 pyinstaller 将我的 python 代码转换为可执行文件时遇到问题。我正在使用 PyQT 4.9.1 和 Python 2.7。
当我尝试构建它时出现错误(Build.py):
Traceback (most recent call last):
File "Build.py", line 1494, in <module>
main(args[0], configfilename=opts.configfile)
File "Build.py", line 1472, in main
build(specfile)
File "Build.py", line 1429, in build
execfile(spec)
File "c:\projects\vibot\vibotUI_07.py", line 270, in <module>
window = viUI()
File "c:\projects\vibot\vibotUI_07.py", line 9, in __init__
QtGui.QMainWindow.__init__(self)
NameError: global name 'QtGui' is not defined
我搜索了谷歌,所有的解决方案都是基于纠正不正确的模块导入,但我已经正确地开始了。
这是我的代码的裁剪版本:
#!/usr/bin/env python
import sys
import os
from PyQt4 import QtCore, QtGui
class viUI(QtGui.QMainWindow):
def __init__(self):
QtGui.QMainWindow.__init__(self)
self.setWindowTitle('test')
self.setObjectName('viMainWindow')
self.resize(400, 600)
self.show()
app = QtGui.QApplication(sys.argv)
window = viUI()
sys.exit(app.exec_())
这是 Makespec.py 文件:
# -*- mode: python -*-
a = Analysis([os.path.join(HOMEPATH,'support\\_mountzlib.py'), os.path.join(HOMEPATH,'support\\useUnicode.py'), 'c:\\projects\\vibot\\vibotUI_07.py'],
pathex=['c:\\Python\\pyinstaller-1.5.1\\pyinstaller-1.5.1'])
pyz = PYZ(a.pure)
exe = EXE( pyz,
a.scripts,
a.binaries,
a.zipfiles,
a.datas,
name=os.path.join('dist', 'vibotUI_07.exe'),
debug=False,
strip=False,
upx=True,
console=True )