marxcell
marxcell

Reputation: 79

can't open .exe after made an app with PyQt5

I have two different problems with my Python script:

  1. I made a simple design with the qt designer and converted it to an .py file. After I run the application in spyder, everything is working fine, but if I close the application, my console is still running and will not close again. I have to restart my console. How can I avoid this?

  2. I converted the .py file to an .exe file with "pyinstaller". If I double click the exe, it will not open and I have no error message. I used the normal command "pyinstaller – onefile -w test.py". I am using Python 3.9 and Spyder as IDE.

This is my code. The code is directly generated from the command "pyuic5 -x test.ui -o test.py".

# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'test.ui'
#
# Created by: PyQt5 UI code generator 5.15.1
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again.  Do not edit this file unless you know what you are doing.


from PyQt5 import QtCore, QtGui, QtWidgets


class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(1280, 720)
        MainWindow.setMinimumSize(QtCore.QSize(1280, 720))
        MainWindow.setMaximumSize(QtCore.QSize(16777215, 16777215))
        font = QtGui.QFont()
        font.setPointSize(11)
        font.setBold(False)
        font.setWeight(50)
        MainWindow.setFont(font)
        MainWindow.setStyleSheet("background-color: rgb(255, 255, 255);")
        MainWindow.setTabShape(QtWidgets.QTabWidget.Rounded)
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setMinimumSize(QtCore.QSize(0, 0))
        font = QtGui.QFont()
        font.setBold(False)
        font.setWeight(50)
        self.centralwidget.setFont(font)
        self.centralwidget.setStyleSheet("")
        self.centralwidget.setObjectName("centralwidget")
        self.gridLayout = QtWidgets.QGridLayout(self.centralwidget)
        self.gridLayout.setContentsMargins(0, 0, 0, 0)
        self.gridLayout.setSpacing(0)
        self.gridLayout.setObjectName("gridLayout")
        self.tabWidget = QtWidgets.QTabWidget(self.centralwidget)
        self.tabWidget.setMinimumSize(QtCore.QSize(0, 0))
        font = QtGui.QFont()
        font.setPointSize(11)
        font.setBold(False)
        font.setWeight(50)
        self.tabWidget.setFont(font)
        self.tabWidget.setObjectName("tabWidget")
        self.tab_ProcessParameters = QtWidgets.QWidget()
        font = QtGui.QFont()
        font.setBold(False)
        font.setWeight(50)
        self.tab_ProcessParameters.setFont(font)
        self.tab_ProcessParameters.setObjectName("tab_ProcessParameters")
        self.gridLayout_2 = QtWidgets.QGridLayout(self.tab_ProcessParameters)
        self.gridLayout_2.setContentsMargins(0, 0, 0, 0)
        self.gridLayout_2.setSpacing(0)
        self.gridLayout_2.setObjectName("gridLayout_2")
        self.frame_background = QtWidgets.QFrame(self.tab_ProcessParameters)
        font = QtGui.QFont()
        font.setPointSize(11)
        font.setBold(False)
        font.setWeight(50)
        self.frame_background.setFont(font)
        self.frame_background.setStyleSheet("background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:1, stop:0 rgba(170, 170, 255, 255), stop:1 rgba(255, 255, 255, 255));\n"
"border-radius: 20px;")
        self.frame_background.setFrameShape(QtWidgets.QFrame.StyledPanel)
        self.frame_background.setFrameShadow(QtWidgets.QFrame.Raised)
        self.frame_background.setObjectName("frame_background")
        self.verticalLayout_2 = QtWidgets.QVBoxLayout(self.frame_background)
        self.verticalLayout_2.setContentsMargins(0, 0, 0, 0)
        self.verticalLayout_2.setSpacing(0)
        self.verticalLayout_2.setObjectName("verticalLayout_2")
        self.gridLayout_2.addWidget(self.frame_background, 0, 0, 1, 1)
        self.tabWidget.addTab(self.tab_ProcessParameters, "")
        self.tab_Visualization = QtWidgets.QWidget()
        self.tab_Visualization.setObjectName("tab_Visualization")
        self.gridLayout_3 = QtWidgets.QGridLayout(self.tab_Visualization)
        self.gridLayout_3.setContentsMargins(0, 0, 0, 0)
        self.gridLayout_3.setSpacing(0)
        self.gridLayout_3.setObjectName("gridLayout_3")
        self.frame_2_background = QtWidgets.QFrame(self.tab_Visualization)
        self.frame_2_background.setStyleSheet("background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:1, stop:0 rgba(170, 170, 255, 255), stop:1 rgba(255, 255, 255, 255));\n"
"border-radius: 20px;")
        self.frame_2_background.setFrameShape(QtWidgets.QFrame.StyledPanel)
        self.frame_2_background.setFrameShadow(QtWidgets.QFrame.Raised)
        self.frame_2_background.setObjectName("frame_2_background")
        self.gridLayout_3.addWidget(self.frame_2_background, 0, 0, 1, 1)
        self.tabWidget.addTab(self.tab_Visualization, "")
        self.gridLayout.addWidget(self.tabWidget, 0, 0, 1, 1)
        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtWidgets.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 1280, 21))
        self.menubar.setObjectName("menubar")
        MainWindow.setMenuBar(self.menubar)
        self.statusbar = QtWidgets.QStatusBar(MainWindow)
        self.statusbar.setObjectName("statusbar")
        MainWindow.setStatusBar(self.statusbar)

        self.retranslateUi(MainWindow)
        self.tabWidget.setCurrentIndex(0)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "Test"))
        self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_ProcessParameters), _translate("MainWindow", "Process Parameters"))
        self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_Visualization), _translate("MainWindow", "Visualization"))


if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    MainWindow = QtWidgets.QMainWindow()
    ui = Ui_MainWindow()
    ui.setupUi(MainWindow)
    MainWindow.show()
    sys.exit(app.exec_())

Upvotes: 0

Views: 699

Answers (1)

user16067425
user16067425

Reputation:

The reason you dont have any error is you used -w. This will hide the the error message. If you want to see the error message first type without -w and see what is the error. And dont use --onefile it is usually problematic. And are you opening the app from build folder? Because if you are the app will not work. Open the app from dist folder.

use this command- pyinstaller filname.py(this will show you the error.(run it from the terminal)) and then open it from dist folder. If there is no error then you can try- pyinstaller filname.py -w to hide the terminal.

Upvotes: 2

Related Questions