Reputation: 841
I have a problem trying to turn my python code into an executable using pyinstaller. I'm using PyQT 4.9.1 and Python 2.7.
I am getting the error when I try and build it (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
I have searched google and all the solutions are based on correcting improper importing of modules, but I already did it properly to begin with.
Here is a cropped version of my code:
#!/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_())
This is the Makespec.py file:
# -*- 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 )
Upvotes: 1
Views: 2497
Reputation: 4510
It looks to me like you're calling Build.py and passing your script as a paramter. I just tested this to see what would happen and got the same output that you posted.
With the current stable PyInstaller (1.5.1) you need to create a spec file first. Instead of Build.py run MakeSpec.py with your script as an argument. This will create a .spec file that you then send to Build.py.
The documentation shows options you can pass to MakeSpec for things like setting an icon under Windows and setting deployment options. These options all go into the spec file so that you just need to call Build.py again when you need to rebuild your application.
Upvotes: 1