Python

How To Convert Python File To Exe Using Pyinstaller

Running a Python Script using the terminal is straightforward, but there are some situations in which you will prefer to hide all the code written in the script inside an executable file. PyInstaller bundles a Python application and all its dependencies into a single package.

Hence Pyinstaller comes into the picture.

PyInstaller works by reading your Python program, analyzing all of the imports it makes, and bundling copies of those imports with your program.

PyInstaller reads in your program from its entry point. For instance, if your program’s entry point is myapp.py, you would run pyinstaller myapp.py to perform the analysis.

PyInstaller can detect and automatically package many common Python packages, like NumPy, but you might need to provide hints in some cases.

After analyzing your code and discovering all the libraries and modules it uses, PyInstaller then generates a ‘spec file’.

Python script with the extension .spec.This file includes details about how your Python app needs to be packed up.

Use the below command to install the pyinstaller.

pip install pyinstaller

Steps to create Executable App in python:

1)Create a python file and write some code and save the file with .py extension (Example:Hellow.py).

2)cd\ to the saved file location.

3) Use the following template to create an executable:

pyinstaller –onefile Hellow.py

4)Run the command in CMD. After executing the step3 from CMD, the executable file will be created in the same location.

5)After step 4, few folders and files will be added by pyinstaller into your App folder.

6)Identify the dist folder and cd in the folder.

PyInstaller

7)Now you will see the Hello App executable in same location. 

Now you will be able to launch your application successfully.

Loading

Translate »