Python file is packaged into pyinstaller of exe

Use pyinstaller to convert your .py file directly into .exe format, and run your program directly on a windows machine without a python environment! !

1. Use pip to install the pyinstaller package on the command line

pip install pyinstaller

2. Download and install the windows extension pywin32 that is needed when the pyinstaler runs

mhammond / pywin32

select the latest version of the download, pay attention to choose the corresponding python version (version) and python bitness (bittedness)

View python version and digits by typing python on the command line

  • The following is the 32 bit of python3.6, you need to download [pywin32-223.win32-py3.6.exe]
Python 3.6.3 ... [MSC v.1900 32 bit (Intel)] on win32
  • The following is the 64 bit of python3.6, you need to download [pywin32-223.win-amd64-py3.6.exe]
Python 3.6.3 ... [MSC v.1900 64 bit (AMD64)] on win32

3. Enter the following command directly in the command line

pyinstaller [opts] yourprogram.py 

Parameter meaning

-F Specifies that only one exe format file is generated after packaging (it is recommended to write this parameter)

-D –onedir creates a directory containing exe files, but will depend on many files (default option)

-c –console, –nowindowed use console, no interface (default)

-w –windowed, –noconsole use window, no console

-p Add a search path to let it find the corresponding library.

-i Change the icon icon of the generated program (such as a program written for girlfriend, change a good-looking icon, the default is very ugly)

Examples

  • For example, you have a python program called test.py, the absolute path is in [D: \ project], and it is packaged into an exe format file
pyinstaller -F D:\project\test.py
  • Conditions are the same as above, if you still want a black box without a console, run secretly in the process
pyinstaller -F -w D:\project\test.py
  • The conditions are the same as above, if you want to change the program icon
pyinstaller -F -w -i D:\project\test.ico D:\project\test.py

Results show

In the directory where your py file is located, generate the build and dist folders. If the -F parameter is selected, then the program you want is in the dist folder, and the build folder can be deleted

Note that pyinstaller can only be converted in a Windows computer environment. At the same time, it is recommended to use English in the path, and do not include Chinese. The low version of pyinstaller may be wrong.

Transfer from https://zhuanlan.zhihu.com/p/38659588

Guess you like

Origin www.cnblogs.com/justjust/p/12729140.html