How to package python script into exe

Preface

In order for others to call the python script we wrote more conveniently without installing the python environment, this blog post will briefly introduce how to package the python script into an exe.

pyinstaller

Many programming language IDEs come with packaging functions by default, and Python packaging is relatively "out of nowhere", and requires additional installation of a third-party packaging tool library. I used the pyinstaller library here.
Enter the following command to install:

pip install PyInstaller

Insert picture description here

Installation method one

In the main program directory, enter the cmd window and enter the following command:

pyinstaller -F genSample.py

Insert picture description here

Installation method two

In order to personalize the exe icon, in the cmd window, enter the following command:

pyinstaller -F -i Batman.ico genSample.py

The icon I used is shown below:
Insert picture description here
PS: The icon path should be in the main program directory

The generated exe looks like this:
Insert picture description here

Guess you like

Origin blog.csdn.net/weixin_42990464/article/details/112475933