Python Forum
PyInstaller: ImportError, no module name 'PyQt4'
Thread Rating:
  • 1 Vote(s) - 2 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PyInstaller: ImportError, no module name 'PyQt4'
#1
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')
Reply
#2
At my main.spec I added:
hiddenimports=['PyQt4', 'PyQt4.uic']

And worked!

But, is this the correct way?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Resolving ImportError: No module named gdb (Python in C++) mandaxyz 3 1,421 Oct-04-2023, 02:43 PM
Last Post: mandaxyz
  Help with pyinstaller "No module named" korenron 9 8,898 Jun-15-2023, 12:20 PM
Last Post: snippsat
  Problem with Pyinstaller. No module named '_tkinter' tonynapoli2309 0 995 May-15-2023, 02:38 PM
Last Post: tonynapoli2309
  ImportError: No module named PIL rudeoil18 9 6,745 Mar-03-2022, 01:25 PM
Last Post: snippsat
  ImportError: No module named coltson 3 3,492 Nov-21-2020, 10:22 AM
Last Post: Superjoe
  error SimpleITK module with pyinstaller PythonCode12 0 1,600 Jul-08-2020, 12:07 PM
Last Post: PythonCode12
  ImportError: No module named pydrive.auth lknights1987 5 5,936 Jun-23-2020, 06:40 PM
Last Post: snippsat
  'No module named tkinter.messagebox' - PyInstaller ironfelix717 7 8,149 Jan-19-2020, 06:56 AM
Last Post: buran
  ImportError: No module named tkinter. kouadio 1 3,671 Oct-08-2019, 10:59 PM
Last Post: Larz60+
  pyinstaller not working with acoustics module pynz 2 2,756 Oct-08-2019, 07:56 AM
Last Post: pynz

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020