Python ---- pyInstaller's common packaging commands

1 Introduction

  1. PyInstaller is a third-party library that can package Python source files under Windows, Linux, Mac OS X and other operating systems. By packaging source files, Python programs can be run in an environment where Python is not installed, or as an independent Files are convenient to transfer and manage.
  2. PyInstaller supports Python 2.7 and Python 3.3+. It can be used on Windows, Mac OS X and Linux, but it is not cross-platform, but if you want to package it into an .exe file, you need to run PyInstaller on the Windows system for packaging; to package it into a mac app, you need to run it on the Mac OS used.

2. Install

pip install pyinstaller

2.1 Attention

1. The PyInstaller library will automatically install the PyInstaller command into the Python interpreter directory, which is the same as the pip or pip3 command path, so it can be used directly.
2. Running PyInstaller on Windows also requires PyWin32 or pypiwin32, of which pypiwin32 will be installed automatically when you install PyInstaller.

3. Basic syntax of pyinstaller packaging command

pyinstaller [options] script[.py]

4. Description of common commands

Order illustrate
-h,–help View the help information for this module
-F,-onefile generate a single executable
-D,–onedir Generate a directory (contains multiple files) as an executable program
-a,–ascii Does not contain Unicode character set support
-d,–debug Generate a debug version of the executable
-w,–windowed,–noconsolc Specifies that the command line window should not be displayed when the program is running (only valid for Windows)
-c,–nowindowed,–console Specifies to use the command line window to run the program (only valid for Windows)
-o YOU,–out=YOUR Specifies the directory where spec files are generated. If not specified, the current directory is used by default to generate the spec file
-p DIR,–path=DIR Sets the path for Python imported modules (similar to setting the PYTHONPATH environment variable). Multiple paths can also be separated using a path separator (semicolon for Windows, colon for Linux)
-n NAME,–name=NAME Specifies the project (generated spec) name. If this option is omitted, the name of the first script's main file will be used as the name of the spec

5. Summary of common packaging commands

Order illustrate
pyinstaller -F xxx.py package an exe
pyinstaller -F -w xxx.py Package an exe without a console
pyinstaller -F -c xxx.py Package an exe with a console
pyinstaller -F -i xxx.ico xxx.py Package an exe with a specified icon

Guess you like

Origin blog.csdn.net/m0_38082783/article/details/130600974