Creating Executable Files from PyQt GUI Applications

Posted by


Creating an executable (exe) from a PyQt GUI application can be a useful way to share your program with others who may not have Python or PyQt installed on their machines. In this tutorial, we will walk through the steps to create an exe file from a PyQt5 GUI application using PyInstaller.

Step 1: Install PyInstaller
The first step is to install PyInstaller, a Python package that can be used to convert Python scripts into standalone executables. You can install PyInstaller using pip by running the following command in your command prompt or terminal:

pip install pyinstaller

Step 2: Create your PyQt GUI application
Next, you will need to have your PyQt5 GUI application ready. If you don’t have one yet, you can create a simple PyQt5 GUI application to test the process. Here is an example of a simple PyQt5 application:

import sys
from PyQt5.QtWidgets import QApplication, QMainWindow, QLabel

class MyWindow(QMainWindow):
    def __init__(self):
        super().__init__()

        self.setWindowTitle("My PyQt App")
        label = QLabel("Hello, PyQt!", self)
        self.setCentralWidget(label)

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

Save this code to a file named my_app.py.

Step 3: Create the exe file
Now that you have your PyQt5 GUI application ready, you can create the exe file using PyInstaller. Open your command prompt or terminal and navigate to the directory where your my_app.py file is located. Run the following command to create the exe file:

pyinstaller --onefile my_app.py

This command will create a dist directory in the same directory as your my_app.py file. Inside the dist directory, you will find an exe file that contains your PyQt5 application.

Step 4: Test the exe file
You can now test the exe file by running it from the command prompt or by double-clicking on it in your file explorer. If everything went well, you should see your PyQt5 application running as expected.

Step 5: Distribute the exe file
Once you have created the exe file for your PyQt5 application, you can distribute it to others who may want to use your program. You can share the exe file directly, or you can package it with an installer to make it easier for users to install the program on their machines.

In this tutorial, we walked through the steps to create an executable (exe) file from a PyQt5 GUI application using PyInstaller. By following these steps, you can easily share your PyQt5 applications with others without requiring them to have Python or PyQt installed on their machines.

0 0 votes
Article Rating

Leave a Reply

26 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
@softdev131
2 hours ago

Thanks so much for this. Finally got pyinstaller to create exe successfully. Have been struggling for so much time after following different videos on youtube.!!

@arthurdeka
2 hours ago

Very good, thanks!!

@ИванЧернышенко-т7ш
2 hours ago

Usually if an Internet user tries to compile his PyQt5 python scripts into an exe file he would like to find out how to make it without ordinary python methods and he hopes the PyQt5 developers have designed their own special way to do that simply.
By the way I don't know why you had to copy some dll files from the plugins directory. When I was "compiling" my scripts I didn't have to copy any files. That is the made exe file could work at once without any errors. Python version I used is 3.7 32bit.

@el07694
2 hours ago

Thanks a lot!
Solved the problem
Cross platform solution, no dependencies!!!

@jubaerhasan4723
2 hours ago

we killed mosquito at exact same time bruh 😂😂😂

@connorminney4691
2 hours ago

Is there a way to bundle the platforms folder with the executable so that it is all in one executable file?

@alephii
2 hours ago

It is unbeliavable how things feel amateur in python.. I am used to program in C, C++, Java, even Visual Basic and only Python is full of those "tricks" to do such basic things!

@UMESHDAVEY
2 hours ago

i am getting this error…..RecursionError: maximum recursion depth exceeded….i am using python 3.7.4 and pyqt 5.9.2

@Itsniteshkumar
2 hours ago

I'm getting fatal error after building exe

@t.jaiii.6326
2 hours ago

hello ajay,
please create tutorial,
second_window back to first_window

@laoren_HK
2 hours ago

What if main.py is already created like:

class class_App(QDialog):
def __init__(self):

super(class_App, self).__init__()
….
app = QApplication(sys.argv)
widget = class_App()

widget.show()
app = sys.exit(app.exec_())
….

And is calling for other Python file ? I could not figure it out how to do. I put all the py file in the dist/Main folder without success.
Thanks for your help

@donha475
2 hours ago

But why would it do this? Why does PyInstaller not have an option to make it work staight away after compiling? Why!???

@darioexequiel22
2 hours ago

Muchísimas gracias !!! me ayudaste un montón!!

@pedrornunes96
2 hours ago

You can make the cmd window automatically disappear while the application is running, using:
pyinstaller –onefile –windowed main.py

@adityaaher5871
2 hours ago

bahot hard bantaiii public.

@diehardAMD
2 hours ago

Well done, sir!

@randyharsh3046
2 hours ago

but will it have problem if not find and installed msi-* files ?

@Amritharaja
2 hours ago

Thanks for simple explanation.

@JO-vj9kn
2 hours ago

Thank You! I also had this exact same error!

@paradiddlepedro
2 hours ago

I freaking love you.

26
0
Would love your thoughts, please comment.x
()
x