ViperSniper0501
ViperSniper0501

Reputation: 310

How to compile PyQt5 program that uses python 3.8

I am trying to compile a simple PyQt5 program into a single EXE file. I have been trying to use fbs for this but I have had no luck. Is there another easy way to do what I am trying to do?

And if the suggestion is to use pyinstaller please explain to me how exactly to do it. I don't do well with vague instructions like "Just use pyinstaller" and they have a link to the wiki. that is not helpful to me because I have already gone there and did not understand it.

Any help is greatly appreciated.

If it helps here is my main.py file:

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

# Form implementation generated from reading ui file 'MainMenu.ui'
#
# Created by: PyQt5 UI code generator 5.13.2
#
# WARNING! All changes made in this file will be lost!


from PyQt5 import QtCore, QtGui, QtWidgets


class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(422, 350)
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.mmlbl = QtWidgets.QLabel(self.centralwidget)
        self.mmlbl.setGeometry(QtCore.QRect(30, 20, 131, 41))
        font = QtGui.QFont()
        font.setPointSize(24)
        font.setItalic(False)
        self.mmlbl.setFont(font)
        self.mmlbl.setObjectName("mmlbl")
        self.Updates_button = QtWidgets.QPushButton(self.centralwidget)
        self.Updates_button.setGeometry(QtCore.QRect(20, 70, 181, 31))
        self.Updates_button.setAcceptDrops(False)
        self.Updates_button.setObjectName("Updates_button")
        self.fwlbutton = QtWidgets.QPushButton(self.centralwidget)
        self.fwlbutton.setGeometry(QtCore.QRect(20, 110, 181, 31))
        self.fwlbutton.setObjectName("fwlbutton")
        self.rmvprosoftbutton = QtWidgets.QPushButton(self.centralwidget)
        self.rmvprosoftbutton.setGeometry(QtCore.QRect(20, 150, 181, 31))
        self.rmvprosoftbutton.setObjectName("rmvprosoftbutton")
        self.auditbutton = QtWidgets.QPushButton(self.centralwidget)
        self.auditbutton.setGeometry(QtCore.QRect(20, 190, 181, 31))
        self.auditbutton.setObjectName("auditbutton")
        self.basicConfbutton = QtWidgets.QPushButton(self.centralwidget)
        self.basicConfbutton.setGeometry(QtCore.QRect(220, 190, 181, 31))
        self.basicConfbutton.setObjectName("basicConfbutton")
        self.UserGroupsButton = QtWidgets.QPushButton(self.centralwidget)
        self.UserGroupsButton.setGeometry(QtCore.QRect(220, 70, 181, 31))
        self.UserGroupsButton.setObjectName("UserGroupsButton")
        self.malrembutton = QtWidgets.QPushButton(self.centralwidget)
        self.malrembutton.setGeometry(QtCore.QRect(220, 150, 181, 31))
        self.malrembutton.setObjectName("malrembutton")
        self.servsetbutton = QtWidgets.QPushButton(self.centralwidget)
        self.servsetbutton.setGeometry(QtCore.QRect(220, 110, 181, 31))
        self.servsetbutton.setObjectName("servsetbutton")
        self.srchmedbutton = QtWidgets.QPushButton(self.centralwidget)
        self.srchmedbutton.setGeometry(QtCore.QRect(20, 230, 181, 31))
        self.srchmedbutton.setObjectName("srchmedbutton")
        self.quit_button = QtWidgets.QPushButton(self.centralwidget)
        self.quit_button.setGeometry(QtCore.QRect(300, 260, 81, 41))
        self.quit_button.setObjectName("quit_button")
        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtWidgets.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 422, 18))
        self.menubar.setObjectName("menubar")
        self.menuAbout = QtWidgets.QMenu(self.menubar)
        self.menuAbout.setObjectName("menuAbout")
        MainWindow.setMenuBar(self.menubar)
        self.statusbar = QtWidgets.QStatusBar(MainWindow)
        self.statusbar.setObjectName("statusbar")
        MainWindow.setStatusBar(self.statusbar)
        self.actionAbout_Creator = QtWidgets.QAction(MainWindow)
        self.actionAbout_Creator.setObjectName("actionAbout_Creator")
        self.actionHow_To_Use = QtWidgets.QAction(MainWindow)
        self.actionHow_To_Use.setObjectName("actionHow_To_Use")
        self.menuAbout.addAction(self.actionAbout_Creator)
        self.menuAbout.addAction(self.actionHow_To_Use)
        self.menubar.addAction(self.menuAbout.menuAction())

        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "Apple CIDR Script Runner"))
        self.mmlbl.setText(_translate("MainWindow", "Main Menu"))
        self.Updates_button.setText(_translate("MainWindow", "Updates"))
        self.fwlbutton.setText(_translate("MainWindow", "Firewall Settings"))
        self.rmvprosoftbutton.setText(_translate("MainWindow", "Remove Prohibited Software"))
        self.auditbutton.setText(_translate("MainWindow", "Audit System"))
        self.basicConfbutton.setText(_translate("MainWindow", "Basic Configurations"))
        self.UserGroupsButton.setText(_translate("MainWindow", "User / Group Settings"))
        self.malrembutton.setText(_translate("MainWindow", "Malware Removal"))
        self.servsetbutton.setText(_translate("MainWindow", "Services Settings"))
        self.srchmedbutton.setText(_translate("MainWindow", "Search For Prohibited Media"))
        self.quit_button.setText(_translate("MainWindow", "Quit"))
        self.menuAbout.setTitle(_translate("MainWindow", "Help"))
        self.actionAbout_Creator.setText(_translate("MainWindow", "About Creator"))
        self.actionHow_To_Use.setText(_translate("MainWindow", "How To Use"))


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_())

Edit: 8/19/2020

I have been able to successfully compile my python program into an EXE file using a program called auto-py-to-exe https://pypi.org/project/auto-py-to-exe/. This program uses pyinstaller and creates a GUI pyinstaller configuration page in your browser. (This makes setting up your pyinstaller command much easier)

Here is what it looks like when running: enter image description here

All you will have to do is fill in your information and hit Convert .PY to .EXE

Also, I recommend that you set the output location of the compiled .exe so you can find it easily.

One more thing. Make sure that when you are doing this, the project that you are working on is on the same hard drive that python is installed on. For example, if you have python installed on your C: drive on windows and your python project is on an external hard drive, it will not work. Move your project over to the Desktop or some where on the C: drive.

Hope that made sense, good luck!

Upvotes: 4

Views: 2461

Answers (1)

joeyipanimation
joeyipanimation

Reputation: 316

Unless you absolutely require python 3.8, you can use still use fbs to build your app.

fbs works with python up to 3.6.x, so the most straight forward & quickest way to get it going is to use a virtual environment.

This is currently my workflow to build & distribute fbs/PyQt5/python36 apps for macOS and win10. I also recommend including all dependencies in your fbs project's ./requirements/base.txt for better/built-in project portability & documentation via. pip install -r ./requirements/base.txt.

Steps

  1. Install python 3.6.x
  2. Install virtual environment of your choice
    • pip install virtualenv
  3. Create & start virtual environment with specific python version
    • virtualenv -p C:/Python36/python.exe venv
    • start ./venv/Scripts/activate.bat (you may have to run this in cmd.exe)
    • Your cmd prompt should now look different (ie. (venv) C:\Users>)
  4. Run fbs app again to make sure no compiler issues with python 3.6.x
    • fbs run
    • Fix any new compiler/syntax issues
  5. If all goes well, attempt to freeze the app again
    • fbs freeze

Upvotes: 3

Related Questions