POSTS

Convert Python(.py) File To Executable (.exe) File

Convert Python(.py) File To Executable (.exe) File

We don't share this python program with everyone, they run this script in an IDLE shell. But I want everyone to be able to run Python scripts without having Python and its libraries installed. If people with zero coding knowledge, it's difficult to run the python program. So, we have to convert the python file into exe file. In this blog we showing to create an executable file with Pyinstaller.

Installing Python

Installing Python is usually easy, and in recent times more Linux and UNIX distributions contain a recent Python. Even few Windows computers particularly in HP now include with Python installed already. If you want to install python, you can find detail explanation in Beginners Guide/Download wiki page, however setup is unremarkable on many platforms. If you earlier installed python, you can pass this step.

Pyinstaller

PyInstaller is a library to convert the python into executable file and all its dependencies into a single executable package. The user able run the executable app without installing a Python or libraries. PyInstaller reads a Python code wrote by you. It will check your code to establish every library of your script needs in flow to execute. Then it collects copies of all those files – including the active Python interpreter – and places them together along with your script in a single directory, or in a single .exe file.

To install pyinstaller in your computer, Type below command in the command prompt or terminal.

* pip install pyinstaller

Converting python file(.py) to .exe using pyinstaller

Now we must to choose to create “one directory” or “one file.” The first one creates a directory with all the dependencies for your script needs to run including the .exe file and second one creates only single executable(.exe) file.

For one file, Type below command in the command prompt or terminal.

* pyinstaller --onefile -w /path/to/yourscript.py

For one directory with all dependencies, Type below command in the command prompt or terminal.

* pyinstaller /path/to/yourscript.py

After executing the command, you have seen a message like “completed successfully.” go into the directory where your python script is placed, and you can find the “dist” folder in that directory. Inside the folder, you’ll find the standalone executable and ‘build’ folder and ‘1.spec’ is of no use. If you want to remove these you can remove, it won’t modify your executable file.

Post Comments

Leave a reply