1

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 )

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

4 Comments

I am using Makespec.py before Build.py, sorry if I left out too much info.
Are you running Build.py on the .spec file that Makespec.py creates?
Sure am. I'll edit in the Makespec.py file, I have a feeling maybe I've entered something incorrectly to make it not find the pyqt module.
Ahh, I misread what you asked, I was running build on the ordinary python file. Sorry about that, my brain has been much lately! Thanks for your help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.