Professional Documents
Culture Documents
to Executable Files
By Guest Contributor • February 21, 2019 •
1 Comment (/converting-python-scripts-to-executable-�les/#disqus_thread
Introduction
In this tutorial, we will explore the conversion of Python scripts to
Windows executable �les in four simple steps. Although there are
many ways to do it, we'll be covering, according to popular opinion,
the simplest one so far.
This tutorial has been designed after reviewing many common errors
that people face while performing this task, and hence contains
detailed information to install and set up all the dependencies as well.
Feel free to skip any step, if you already have those dependencies
installed. Without any further ado, let's start.
$ curl --version
If the command above returns a curl version, you can skip the next
instructions in this step. As for the rest of you, you can install curl by
following these three steps:
1. Go to https://curl.haxx.se/dlwiz/?type=bin&os=Win64&�av=-&
ver=*&cpu=x86_64 (https://curl.haxx.se/dlwiz/?type=bin&
os=Win64&�av=-&ver=*&cpu=x86_64)
2. Download the curl package which matches your system's
speci�cations (32-bit/64-bit)
3. Unzip the �le and go to the bin folder, you can �nd the curl.exe
�le there
However, this means that you can only use the curl command in that
particular folder. In order to be able to use the curl command from
anywhere on your machine, right-click on curl.exe, click on
"Properties" and copy the "Location" value. After that, right-click on
"My PC" and click on "Properties". In the option panel on the left,
select the option "Advanced System Settings". It has been highlighted
in the screenshot below.
In the next window, �nd and double click on the user variable named
"Path", then click on "New". A new text box will be created in that
window; paste the "Location" value of the "curl.exe" �le that you
copied earlier, and then click on 'OK'.
$ curl --version
$ pip --version
If the command above returned a pip version, you can skip the next
instructions in this step.
As for the rest, you can install pip by running the following two
commands in the command prompt:
$ python get-pip.py
That's it. Pip has now been installed to your local machine! You can
run the following command for con�rmation:
$ pip --version
Before moving to the next step, you need to repeat what we did for
curl.exe so that you can access the pip command from anywhere in
your machine, but this time we'll be doing so for "pip.exe".
Hit the Windows key and search for "pip.exe", then right-click on the
�rst search result and click on "Open File Location", it will take you to
the folder in which that �le is located. Right-click on the "pip.exe" �le
and then select "Properties". After that, copy the "Location" value and
paste it in the Path variable just like we did in Step 1.
Subscribe
$ pyinstaller --version
This step marks the end of all installations. In the next step, we'll be
converting our Python �les to an executable with just a single
command.
Step 4: Convert Python Files to
Executables
This is the last step. We'll use pyinstaller to convert our .py �les to
.exe with a single command. So, let's do it!
Open up the command prompt and navigate to the directory that your
Python �le/script is located in. Alternatively, you can open that
directory using File Explorer, right-click + shift and then select "Open
Command Prompt in this folder". Before converting your �le, you
should check that your �le works as expected. For that purpose, I have
written a basic Python script which prints the number 10 when
executed.
Let's run the script and see if it works �ne before converting it to an
executable �le. Run the following command on your command
prompt:
$ python name_of_your_file.py
$ pyinstaller --onefile <file_name>.py
Let's now run our executable �le to see if the procedure worked!
A little tip, if your executable �le closes too fast for you to notice the
output, you can add an input() line at the end of your Python �le,
which keeps the prompt open while waiting for using input. That is
how I was able to take a screenshot of my output as well.
Conclusion
In this tutorial, we discussed in detail the conversion of Python scripts
to executable �les using Python's pyinstaller library in four steps. We
started by installing cURL, followed by pip and pyinstaller. Lastly, we
converted a sample Python �le to executable to ensure that the
procedure works on Windows.
python (/tag/python/)
https://twitter.com
/share?text=Converting%20Python%20Scripts%20to%20Executable%20Files&
url=https://stackabuse.com/converting-python-scripts-to-executable-�les/)
https://www.facebook.com/sharer/sharer.php?u=https://stackabuse.com
/converting-python-scripts-to-executable-�les/)
https://plus.google.com/share?url=https://stackabuse.com/converting-
python-scripts-to-executable-�les/)
https://www.linkedin.com/shareArticle?mini=true%26url=https:
//stackabuse.com/converting-python-scripts-to-executable-
�les/%26source=https://stackabuse.com)
(/author/guest/)
About Guest Contributor (/author
/guest/)
Subscribe
Comments Community
1 Login
Name
Horlugingin Ayoade
⚑
3 months ago
ALSO ON STACKABUSE
Previous Post : Python Performance Optimization (/python-performance-optimization/)
Ad
Follow Us
Twitter (https://twitter.com/StackAbuse)
Facebook (https://www.facebook.com/stackabuse)
RSS (https://stackabuse.com/rss/)
Newsletter
Subscribe
Ad
Our Sponsors
(https://stackabu.se/digitalocean)
(https://stackabu.se/triplebyte)
(https://stackabu.se/triplebyte)
Recent Posts
Solving Sequence Problems with LSTM in Python's Keras Library (/solving-
sequence-problems-with-lstm-in-pythons-keras-library/)
Tags
bash (/tag/bash/)
Follow Us
Twitter (https://twitter.com/StackAbuse)
Facebook (https://www.facebook.com/stackabuse)
RSS (https://stackabuse.com/rss/)