0

I have a project with a GUI created in Qt Designer and compiled with pyuic. So I import QtCore and QtGui from PyQt4.

The script runs OK.

I need an executable file. The tool is PyInstaller, target platforms - Linux and Windows. I've tried and had a success once. Then I developed a project for some time and now... I cannot make an executable - it crashes with

ImportError: No module named QtCore

The problem is that I cannot compare current project with the old one. And I'm not sure how the environment in my PC has changed.

So I have to understand why PyInstaller makes an executable with no error messages - but the program crashes. Or how to help PyInstaller (I've read manual and tried a lot from it but to no avail).

Here is a simplified version of my project (actually a single file) that has the main feature: it runs OK from Python and crashes as standalone program.

#!/usr/bin/python
# -*- coding: utf-8 -*-
""" test script to learn PyInstaller usage
"""
import sys
from PyQt4 import QtCore
from PyQt4 import QtGui


class Main(QtGui.QMainWindow):
    def __init__(self):
        QtGui.QMainWindow.__init__(self)
        self.ui = Ui_ADCmonitor()
        self.ui.setupUi(self)
        self.exitAction = QtGui.QAction('Exit', self)
        self.exitAction.setShortcut('Ctrl+Q')
        self.exitAction.triggered.connect(self.close)
        toolbar = self.addToolBar('Exit')
        toolbar.addAction(self.exitAction)
        self.refresh = QtCore.QTimer()
        self.status_freeze_timer = QtCore.QTimer()
        self.update_data()

    def update_data(self):
        self.status_refresh('Ok')
        self.refresh.singleShot(200, self.update_data)

    def status_refresh(self, msg):
        self.ui.statusbar.showMessage(msg)


class Ui_ADCmonitor(object):
    def setupUi(self, ADCmonitor):
        ADCmonitor.setObjectName("ADCmonitor")
        ADCmonitor.resize(300, 300)
        self.statusbar = QtGui.QStatusBar(ADCmonitor)
        self.statusbar.setObjectName("statusbar")
        ADCmonitor.setStatusBar(self.statusbar)
        QtCore.QMetaObject.connectSlotsByName(ADCmonitor)
        ADCmonitor.setWindowTitle("ADC Monitor")


if __name__ == "__main__":
    app = QtGui.QApplication(sys.argv)
    window = Main()
    window.show()
    sys.exit(app.exec_())

And please don't propose me to use other dist utilities. I tried some of them, I've chosen PyInstaller and I'd like to use it.

drvlas
  • 423
  • 3
  • 7
  • 18
  • possible duplicate? http://stackoverflow.com/q/23709651/541038 – Joran Beasley Sep 14 '15 at 18:29
  • or maybe http://stackoverflow.com/questions/8548904/pyinstaller-error-with-pyqt-when-trying-to-build-onefile ? it looks like there are lots of hits on google with potential solutions have you tried them? what version of pyinstaller are you using? what OS are you building on? what version of python? what version of pyQT? – Joran Beasley Sep 14 '15 at 18:30
  • 1
    Joran, Maybe the 1-st link is an answer. I'll have to try to install PyInstaller 2.2. My OS is Linux Mint, PyInstaller is 2.1, Python is 2.7.5+ – drvlas Sep 14 '15 at 19:21
  • sorry :/ I wish I could help more ... the second answer actually looks more applicable to me ... but maybe not – Joran Beasley Sep 14 '15 at 19:42
  • You really helped me, Joran. Thanks a lot! – drvlas Sep 14 '15 at 19:56

1 Answers1

1

So, the problem is in a PyInstaller 2.1 bug - as Joran Beasley supposed.

Solution:

sudo pip install git+https://github.com/pyinstaller/pyinstaller.git

And bingo!

pyinstaller myscript.py makes correct exec.

drvlas
  • 423
  • 3
  • 7
  • 18