Python Forum

Full Version: PyInstaller: ImportError, no module name 'PyQt4'
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I 'm trying to make an exe out of my python code with PyInstaller.
My code is this:
from PyQt4 import uic, QtGui, QtCore
import sys

qtCreatorFile = "F:/Documents and Settings/Administrator/My Documents/PycharmProjects/repairdevicesv9/main.ui"

Ui_MainWindow, QtBaseClass = uic.loadUiType(qtCreatorFile)

class MyApp(QtGui.QMainWindow, Ui_MainWindow, QtGui.QWidget):
   def __init__(self):
       QtGui.QMainWindow.__init__(self)
       Ui_MainWindow.__init__(self)

       self.setupUi(self)
       self.setWindowFlags(self.windowFlags() & ~QtCore.Qt.WindowMaximizeButtonHint)

if __name__ == "__main__":    
   app = QtGui.QApplication(sys.argv)
   window = MyApp()
   window.show()
   sys.exit(app.exec_())
The most strange of all is that it worked yesterday for a couple of times, and then appeared this error, even though the code remained unchanged!

I had PyInstaller, the normal version, installed through pip.
I read in related (with this error) topics, that the dev version of PyInstaller might help.
I installed it (through pip) but the error remains.
Is there some work around?


(My project is in F:/Documents and Settings/Administrator/My Documents/PycharmProjects/repairdevicesv9/, I put the full path at line 4 because otherwise PyInstaller won't find it)

The procedure I follow is (at cmd):
cd F:\Documents and Settings\Administrator\My Documents\PycharmProjects\repairdevicesv9\
pyi-makespec main.spec
This builds the spec file. Then:

pyinstaller main.spec


If I do it without a spec file, it gives no error(but I have to use a spec file because I want to include some images).

This is my main.spec:
Quote:block_cipher = None


a = Analysis(['main.spec'],
            pathex=['F:\\Documents and Settings\\Administrator\\My Documents\\PycharmProjects\\repairdevicesv9'],
            binaries=[],
            datas=[],
            hiddenimports=[],
            hookspath=[],
            runtime_hooks=[],
            excludes=[],
            win_no_prefer_redirects=False,
            win_private_assemblies=False,
            cipher=block_cipher)
pyz = PYZ(a.pure, a.zipped_data,
            cipher=block_cipher)
exe = EXE(pyz,
         a.scripts,
         exclude_binaries=True,
         name='main',
         debug=False,
         strip=False,
         upx=True,
         console=True )
coll = COLLECT(exe,
              a.binaries,
              a.zipfiles,
              a.datas,
              strip=False,
              upx=True,
              name='main')
At my main.spec I added:
hiddenimports=['PyQt4', 'PyQt4.uic']

And worked!

But, is this the correct way?