Photo by Fotis Fotopoulos on Unsplash
How to --> Convert PY --> EXE
·Dec 21, 2021·
2 min read
Play this article
One of the most frequent asked questions from Python Programmers
'How to Convert PY to EXE?'
The most simplest answer just to say, it is possible, and you can do it, in just a few moments and clicks!
For todays example, I am having the following Python File :)
My Python File is called
name = input('What is your name?') age = input('What is your age?') hobby = input('What is your hobby?') print('Hello ' + name + '! You are ' + age + ' years old. Your hobby is ' + hobby + '.')
So, let us get into it
1. So first, locate the folder your Python file is located in. And type in the path
powershell and press enter.
2. Enter this command in PowerShell
pip install pyinstaller
pyinstaller should install, I installed it before.
3. In the PowerShell Window, write the following command & press enter, edit the file name to avoid errors
So for example
pyinstaller --onefile filename.py
This is an example, so, because my python file name is main.py, I will enter the following command
pyinstaller --onefile main.py
After the command is executed we should see this message
And in our folder, we find some new folders too
4. Go into the
dist folder. You will find the exe with your file name. Like main.exe.
Double-click the exe, and it should run as a Python File.
When you run the exe, it runs, but when it ends, it closes instantly, so you cannot read the result, to fix the issue, end your Python Code with