ThePyNoob
Published in

ThePyNoob

Creating a “.EXE” from a “.PY” file.

Photo by heylagostechie on Unsplash

Hello World.
There is no GitHub file for this post, because the whole code will be included in this post.

If you noticed, all my github project always include an executable, I always do that to be helpful. If someone comes across one of the simple programs that I wrote and wants to use it, I don’t want that person to have to download an IDE / IDLE to compile and run the program, I want them to be able to simply double click it. That’s where creating an executable comes in.

My Set Up.
The host machine is a Windows 10 Machine.
I use PyCharm for my coding, which provides me with a lovely “file.py” file.

What Do I Need The Program To Do.
-To convert my “.py” file to a “.exe” file.
Alright, let’s do this.

// It’s a 3 Step Process.
STEP ONE: Install PIP
If you already have ‘pip’ installed on your machine, you can skip this one.
You can check if it is installed by opening up your CMD terminal and type: pip
If its not install I recommend installing it this way
-Install / Re-Install Python.
-Make sure to select the option to “Install pip”.
-Make sure to select its “Path”.

STEP TWO: Install PyInstaller.
-Open you CMD terminal.
pip install pyinsaller
-That will take a few minutes, so just let it run until its completed.

NOTE:
Once you’ve completed those two steps, you don’t have to do them again, they were a one-time thing. So on your Next EXE conversion, you can go straight to Step Three.

STEP THREE: Creating The EXE file.
-Open your CMD terminal.
-Navigate to where your .py file is.
cd /path/to/your/file

-If you have a Graphical program, run this command:
pyinstaller --onefile -w YourFile.py

-If you have a Non-Graphical program, run the command below(This is the one I’ve used for all of mine).
-It’s the same command, only without the “-w”:
pyinstaller --onefile YourFile.py

This step will take a few minutes to run, depending on how large your program is, and you will see that it will create several other files and folders in the location of where your .py file is.

Location of your file:
-Navigate to where your .py file is.
-YourFile.exe will be in the “dist” folder.

You Are Done
That’s it, you now have an executable file of your python file. Now just run it to make sure that everything works as it should.

Keep In Mind:
-If your original script relied on external files (like reading from text file), then you need to have that file in the same location as your .exe file.
-Also if your executable CREATS an output of some kind, if the location isn’t hard-coded, then it will output it to the same location that the executable is running from.

I hope this post has given you some ideas.
This has been ryn0f1sh, The PyNoob.
[R/F]
End Of Line.

--

--

--

Documenting my Pythonic journey.

Recommended from Medium

Running Folding@home on Amazon EC2 instances

How to call the Financial Modeling Prep API with Python

Pushing data into Cosmos DB using spark data frame

Quick Look at Google Cloud Vision API on Android

How to speed up app testing?

User Stories: Making the Vertical Slice

10+ Best AWS Training Online Courses — Prepare For AWS Certification

Kubernetes on TV: Watch How Your Services are Operating in Production

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
[ ryn0f1sh ]

[ ryn0f1sh ]

Sudanese / Blogger / Pen Tester / Python Charmer / Lover Of Outer Space / Coffee Drinker (https://www.buymeacoffee.com/execodeable)

More from Medium

IMAGE SEGMENTATION USING UNETS

Insurance Claims — Fraud Detection

Insurance Claims -Fraud Detection By: Syed Mugera Bilal

Using DRA Repositories

Red Team Lab Integration