Hi Pythonistas!
Today we will learn how to make an executable from a python script. We are using a package called pyinstaller. This package has support in Windows, Linux, and mac. Let us div into the code
Installation
pip install pyinstaller
For the script I am using the same code as the previous post.
Code
from faker import Faker
fake = Faker(['ja_JP'])
for _ in range(10):
print(fake.name())
Command
pyinstaller --onefile faker_test.py --name fakerexecutable
name is an optional parameter if we don't pass the name executable has also named as the script.
onefile is an optional parameter if it passed the final output will be single file with all the dependencies are packed else it will be folder
Once the command is executed then a dist folder will be created inside there will be our executable.
Run executable
If you are using unix like OS we can run by
./fakerexecutable
If you are using window we run by double clicking the file
Output
佐藤 裕美子
橋本 和也
中島 浩
吉田 幹
林 翔太
太田 英樹
佐藤 知実
山本 花子
山口 七夏
佐々木 香織
To learn about please visit the official documentation
I Hope you have learned something from the post. Please share you valuable suggestions with afsal@parseltongue.co.in