python study Notes Package the python source file as exe file of pyinstaller

  • 2020-09-16 07:36:18
  • OfStack

Use of the pyinstaller library

PyInstaller is a 10-point useful third library, which can package Python source files under Windows, Linux, Mac OS X and other operating systems. By packaging the source files, the Python program can run in an environment without Python installed, or it can be easily delivered and managed as a separate file. PyInstaller needs to be installed from the command line (console) using the pip tool, as follows:

:\>pip install pyinstaller 


:\>pip3 install pyinstaller 

PyInstaller http is the official web site url: / / www pyinstaller. org /. The PyInstaller library automatically installs the PyInstaller command into the Python interpreter directory, the same path as the pip or pip3 command, so you can use it directly. It is easy to use the PyInstaller library 10, please note that since PyInstaller does not support the existence of English period (.) in the source file, assume that the file is in the D:\codes directory, the command is as follows:



:\>pyinstaller D:\codes\ 

After execution, dist and build folders are generated in the directory where the source files are located. The build directory is where pyinstaller stores temporary files and can be safely removed. The final package is in the dpython directory within dist. The other files in the directory are dynamic link libraries for the executable dpython.exe. The -ES51en parameter can be used to generate a separate executable for the Python source file, as follows:

:\>pyinstaller -F 

After execution, the dpython. exe file appears in the dist directory. It does not have any dependent libraries. Using the PyInstaller library requires attention to the following issues: no Spaces and periods (.) in the file path; The source file must be es60EN-8 encoded, and other encoding types are not supported. Source files prepared by IDLE are saved as UTF-8 encoding form, which can be used directly. PyInstaller has 1 common parameter, as shown below:

-ES66en, --help View Help
-v, --version

View the PyInstaller version

clean cleans up temporary files during packaging
-D, --onedir
By default, generate the dist directory
-F, --onefile
Only separate package files are generated in the dist folder
-p DIR -paths Adds the third library path used for Python files
-i < .ico or .exe,ID or .icns > ,--icon < .ico or .exe,ID or .icns > Specifies the icon (icon) file used by the wrapper

The PyInstaller command does not need to add code to the Python source file, it just needs to be packaged on the command line. The -ES104en parameter is most commonly used, and for source files that contain a third library, you can use -ES105en to add the path where the third library is located. If the third library is installed by pip and is in the Python environment directory, the -ES108en parameter is not required.

Related articles: