How Python generate windows exe executable file

Why should generate an executable file

  • No need to install the corresponding programming environment
  • Your application can be closed-source
  • Users can quickly and directly use

Strapping Tools

  • pyinstaller

Installation pyinstaller

If your network is stable, usually directly use the following command to install:

pip install pyinstaller

Of course, you can also download pyinstaller source package, the package directory and then enter the following command, it can also be installed (provided that the need to install setuptools):

python setup.py install

Installation process as shown in FIG.

image description

Check the pyinstaller successful installation:

Only you need to do one of the following commands to:

pyinstaller --version
pyinstaller -v

If the following interface appears, it shows that the installation was successful

image description

pyinstaller effect parameters

  • Generating a single executable file represents -F
  • -D -onedir create a directory that contains exe file, but a lot will depend on the file (the default option)
  • -w represent remove the console window, which is very useful when a GUI interface. But if it is a command line program, then it would put this option to remove it
  • -c -console, -nowindowed using the console, no interface (default)
  • -p means that you need to load your own custom class path, generally less than
  • -i represents the icon of the executable file
  • Other parameters, you can pyinstaller --helpsee

Start packing

Enter the directory where python script needs to be packaged, and then execute the following command:

python -F -i favicon.ico nhdz.py

FIG implementation is as follows:

image description

Packed result

After the package is complete, go to the directory, you will find the current more __pycache __, build, dist, nhdz.spec four folders or files, which packaged exe application under the dist directory, you enter you can see, you can he directly copied elsewhere, shown below, it is a complete directory packetized:

image description

Exe application execution

Because exe application is an executable file, and so can simply double-click operation, operation results as shown below:

image description

Here, exe file has been regarded as students complete package, and can run, and if you want to run on other platforms, you only need to copy the following files to dist

ICO Icon Maker

Front need to use ICO icon, you can search online "ICO generated online", you can click on ICO icons made production on it, and then save is also OK

Guess you like

Origin www.cnblogs.com/gdg87813/p/11226065.html