1. 程式人生 > >Python - 使用Pyinstaller將Python代碼生成可執行文件

Python - 使用Pyinstaller將Python代碼生成可執行文件

設置 uniq use hive tor 64bit cep des pre

1 - Pyinstaller簡介

Home-page: http://www.pyinstaller.org
PyInstaller是一個能夠在多系統平臺(Windows、*NIX、Mac OS)上將Python程序凍結(打包)為獨立可執行文件的工具。

  • 可以捆綁所需的第三方庫,並可與絕大多數常見的庫和框架配合使用;
  • 可以與Python2.7和3.3-3.6協同工作,由於透明壓縮而構建了更小的可執行文件;
  • 使用OS支持來加載動態庫,從而確保完全兼容;

2 - Pyinstaller安裝

$ pip3 install --proxy=10.144.1.10:8080 pyinstaller
Collecting
pyinstaller Using cached PyInstaller-3.3.1.tar.gz Requirement already satisfied: setuptools in c:\python36\lib\site-packages (from pyinstaller) Collecting pefile>=2017.8.1 (from pyinstaller) Using cached pefile-2017.11.5.tar.gz Collecting macholib>=1.8 (from pyinstaller) Using cached macholib-1.9-py2.py3-none-any.whl Collecting
future (from pyinstaller) Using cached future-0.16.0.tar.gz Collecting pypiwin32 (from pyinstaller) Downloading pypiwin32-223-py3-none-any.whl Collecting altgraph>=0.15 (from macholib>=1.8->pyinstaller) Using cached altgraph-0.15-py2.py3-none-any.whl Collecting pywin32>=223 (from pypiwin32->
pyinstaller) Downloading pywin32-223-cp36-cp36m-win_amd64.whl (9.0MB) 100% |████████████████████████████████| 9.0MB 75kB/s Installing collected packages: future, pefile, altgraph, macholib, pywin32, pypiwin32, pyinstaller Running setup.py install for future ... done Running setup.py install for pefile ... done Running setup.py install for pyinstaller ... done Successfully installed altgraph-0.15 future-0.16.0 macholib-1.9 pefile-2017.11.5 pyinstaller-3.3.1 pypiwin32-223 pywin32-223 $ pip3 show pyinstaller Name: PyInstaller Version: 3.3.1 Summary: PyInstaller bundles a Python application and all its dependencies into a single package. Home-page: http://www.pyinstaller.org Author: Giovanni Bajo, Hartmut Goebel, David Vierra, David Cortesi, Martin Zibricky Author-email: [email protected] License: GPL license with a special exception which allows to use PyInstaller to build and distribute non-free programs (including commercial ones) Location: c:\python36\lib\site-packages Requires: setuptools, pefile, macholib, future

3 - 使用Pyinstaller

3-1 文件及目錄

通過“pyinstaller [...] scriptname”方式運行,將會默認生成以下文件及目錄:

.spec

  • 打包配置文件,事後可刪除
  • 控制參數:--specpath DIR Folder to store the generated spec file (default: current directory)
  • 使用pyinstaller時,默認會在當前的路徑下生成一個以spec為後綴的打包配置文件,pyinstaller依據spec文件的內容來創建exe文件;
  • 正常情況下,不需要去修改這個spec文件,除非需要打包其他數據文件;

build/

  • 存放過程文件,事後可刪除
  • 控制參數:--workpath WORKPATH Where to put all the temporary work files, .log, .pyz and etc. (default: .\build)

dist/

  • 存放捆綁的應用程序,包含生成好的exe文件
  • 控制參數:--distpath DIR Where to put the bundled app (default: .\dist)

3-2 常用命令選項

--distpath DIR        # 指定捆綁應用程序的存放路徑和目錄
--workpath WORKPATH        # 指定存放臨時文件的路徑和目錄
-y, --noconfirm        # 無詢問覆蓋目錄
--clean        # 清除緩存文件
--log-level LEVEL        # 指定日誌等級


-D, --onedir        # 生成一個包含exe文件和依賴文件的目錄                
-F, --onefile        # 只生成一個包含依賴的exe格式文件
--specpath DIR        # 指定存放spec文件的目錄
-n NAME, --name NAME        # 指定輸出文件名稱(默認為第一個文件名)
-c, --console, --nowindowed        # 使用控制臺(命令行窗口)作為標準IO(默認)
-w, --windowed, --noconsole        # 不使用控制臺(命令行窗口)作為標準IO(不適用*NIX系統)
-i <FILE.ico or FILE.exe,ID or FILE.icns>, --icon <FILE.ico or FILE.exe,ID or FILE.icns>    # 指定應用ico圖標


--add-data <SRC;DEST or SRC:DEST>        # !
--add-binary <SRC;DEST or SRC:DEST>        # !
-p DIR, --paths DIR        # 指定搜索路徑,用‘;‘分割多個路徑
--exclude-module EXCLUDES        # 指定不打包的模塊
                        Optional module or package (the Python name, not the
                        path name) that will be ignored (as though it was not
                        found). This option can be used multiple times.
--key KEY        # 加密python字節碼

4 - Pyinstaller示例

4-1 基本用法

python代碼

guowli@5CG450158J MINGW64 /d/Anliven-Running/TempTest
$ cat GUI_Tkinter.py
#! python3
# -*- coding: utf-8 -*-
from tkinter import *
import tkinter.messagebox as messagebox


class Application(Frame):  # 從Frame派生一個Application類,這是所有Widget的父容器
    def __init__(self, master=None):
        Frame.__init__(self, master)
        self.pack()  # pack()方法把Widget加入到父容器中,並實現布局
        self.createWidgets()

    def createWidgets(self):
        self.helloLabel = Label(self, text=‘This is a sample.‘)  # 創建一個Label
        self.helloLabel.pack()
        self.nameInput = Entry(self)
        self.nameInput.pack()
        self.alertButton = Button(self, text=‘Hi‘, command=self.hello)  # 創建一個Button,點擊按鈕,觸發hello()
        self.alertButton.pack()
        self.quitButton = Button(self, text=‘Quit‘, command=self.quit)  # 點擊按鈕,觸發self.quit(),程序退出
        self.quitButton.pack()

    def hello(self):
        name = self.nameInput.get() or ‘world‘  # 獲得用戶輸入的文本
        messagebox.showinfo(‘Message‘, ‘Hello, %s % name)  # 彈出消息對話框


app = Application()  # 實例化Application
app.master.title(‘Hello World‘)  # 設置窗口標題
app.mainloop()  # 主消息循環

# ### Tkinter
# Python內置的是支持Tk的Tkinter,無需安裝任何包,可以直接使用,能夠滿足基本的GUI程序的要求;
# 如果是非常復雜的GUI程序,建議用操作系統原生支持的語言和庫來編寫;
# 常見的第三方圖形界面庫包括Tk、wxWidgets、Qt、GTK等;

生成可執行文件

guowli@5CG450158J MINGW64 /d/Anliven-Running/TempTest
$ ls -l
total 4
-rwxr-xr-x 1 guowli 1049089 1574 Feb 11 09:31 GUI_Tkinter.py*

guowli@5CG450158J MINGW64 /d/Anliven-Running/TempTest
$

guowli@5CG450158J MINGW64 /d/Anliven-Running/TempTest
$ pyinstaller -F -w GUI_Tkinter.py
205 INFO: PyInstaller: 3.3.1
207 INFO: Python: 2.7.12
207 INFO: Platform: Windows-7-6.1.7601-SP1
208 INFO: wrote D:\Anliven-Running\TempTest\GUI_Tkinter.spec
217 INFO: UPX is not available.
220 INFO: Extending PYTHONPATH with paths
[‘D:\\Anliven-Running\\TempTest‘, ‘D:\\Anliven-Running\\TempTest‘]
223 INFO: checking Analysis
223 INFO: Building Analysis because out00-Analysis.toc is non existent
223 INFO: Initializing module dependency graph...
236 INFO: Initializing module graph hooks...
365 INFO: running Analysis out00-Analysis.toc
392 INFO: Adding Microsoft.VC90.CRT to dependent assemblies of final executable
  required by c:\python27\python.exe
2701 INFO: Found C:\WINDOWS\WinSxS\Manifests\amd64_policy.9.0.microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.1_none_3da38fdebd0e6822.manifest
2705 INFO: Found C:\WINDOWS\WinSxS\Manifests\amd64_policy.9.0.microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.4148_none_acd0e4ffe1daef0a.manifest
2710 INFO: Found C:\WINDOWS\WinSxS\Manifests\amd64_policy.9.0.microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.4940_none_acd19a1fe1da248a.manifest
2806 INFO: Searching for assembly amd64_Microsoft.VC90.CRT_1fc8b3b9a1e18e3b_9.0.30729.4940_none ...
2806 INFO: Found manifest C:\WINDOWS\WinSxS\Manifests\amd64_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.4940_none_08e4299fa83d7e3c.manifest
2809 INFO: Searching for file msvcr90.dll
2809 INFO: Found file C:\WINDOWS\WinSxS\amd64_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.4940_none_08e4299fa83d7e3c\msvcr90.dll
2810 INFO: Searching for file msvcp90.dll
2810 INFO: Found file C:\WINDOWS\WinSxS\amd64_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.4940_none_08e4299fa83d7e3c\msvcp90.dll
2812 INFO: Searching for file msvcm90.dll
2812 INFO: Found file C:\WINDOWS\WinSxS\amd64_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.4940_none_08e4299fa83d7e3c\msvcm90.dll
2908 INFO: Found C:\WINDOWS\WinSxS\Manifests\amd64_policy.9.0.microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.1_none_3da38fdebd0e6822.manifest
2909 INFO: Found C:\WINDOWS\WinSxS\Manifests\amd64_policy.9.0.microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.4148_none_acd0e4ffe1daef0a.manifest
2911 INFO: Found C:\WINDOWS\WinSxS\Manifests\amd64_policy.9.0.microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.4940_none_acd19a1fe1da248a.manifest
2912 INFO: Adding redirect Microsoft.VC90.CRT version (9, 0, 21022, 8) -> (9, 0, 30729, 4940)
3044 INFO: Caching module hooks...
3070 INFO: Analyzing D:\Anliven-Running\TempTest\GUI_Tkinter.py
8287 INFO: Processing pre-safe import module hook   _xmlplus
8536 INFO: Processing pre-find module path hook   distutils
9615 INFO: Loading module hooks...
9615 INFO: Loading module hook "hook-distutils.py"...
9618 INFO: Loading module hook "hook-sysconfig.py"...
9619 INFO: Loading module hook "hook-xml.py"...
9769 INFO: Loading module hook "hook-httplib.py"...
9770 INFO: Loading module hook "hook-_tkinter.py"...
10214 INFO: checking Tree
10217 INFO: Building Tree because out00-Tree.toc is non existent
10217 INFO: Building Tree out00-Tree.toc
10470 INFO: checking Tree
10470 INFO: Building Tree because out01-Tree.toc is non existent
10470 INFO: Building Tree out01-Tree.toc
10498 INFO: Loading module hook "hook-encodings.py"...
11378 INFO: Looking for ctypes DLLs
11409 INFO: Analyzing run-time hooks ...
11412 INFO: Including run-time hook ‘pyi_rth__tkinter.py‘
11421 INFO: Looking for dynamic libraries
11786 INFO: Looking for eggs
11787 INFO: Using Python library C:\WINDOWS\system32\python27.dll
11787 INFO: Found binding redirects:
[BindingRedirect(name=u‘Microsoft.VC90.CRT‘, language=None, arch=u‘amd64‘, oldVersion=(9, 0, 21022, 8), newVersion=(9, 0, 30729, 4940), publicKeyToken=u‘1fc8b3b9a1e18e3b‘)]
11796 INFO: Warnings written to D:\Anliven-Running\TempTest\build\GUI_Tkinter\warnGUI_Tkinter.txt
11839 INFO: Graph cross-reference written to D:\Anliven-Running\TempTest\build\GUI_Tkinter\xref-GUI_Tkinter.html
12016 INFO: checking PYZ
12016 INFO: Building PYZ because out00-PYZ.toc is non existent
12017 INFO: Building PYZ (ZlibArchive) D:\Anliven-Running\TempTest\build\GUI_Tkinter\out00-PYZ.pyz
12598 INFO: Building PYZ (ZlibArchive) D:\Anliven-Running\TempTest\build\GUI_Tkinter\out00-PYZ.pyz completed successfully.
12664 INFO: checking PKG
12664 INFO: Building PKG because out00-PKG.toc is non existent
12664 INFO: Building PKG (CArchive) out00-PKG.pkg
12828 INFO: Redirecting Microsoft.VC90.CRT version (9, 0, 21022, 8) -> (9, 0, 30729, 4940)
16441 INFO: Building PKG (CArchive) out00-PKG.pkg completed successfully.
16570 INFO: Bootloader c:\python27\lib\site-packages\PyInstaller\bootloader\Windows-64bit\runw.exe
16570 INFO: checking EXE
16572 INFO: Building EXE because out00-EXE.toc is non existent
16572 INFO: Building EXE from out00-EXE.toc
16573 INFO: Appending archive to EXE D:\Anliven-Running\TempTest\dist\GUI_Tkinter.exe
16603 INFO: Building EXE from out00-EXE.toc completed successfully.

guowli@5CG450158J MINGW64 /d/Anliven-Running/TempTest
$

guowli@5CG450158J MINGW64 /d/Anliven-Running/TempTest
$ ls -l
total 8
drwxr-xr-x 1 guowli 1049089    0 Feb 27 15:09 build/
drwxr-xr-x 1 guowli 1049089    0 Feb 27 15:09 dist/
-rwxr-xr-x 1 guowli 1049089 1574 Feb 11 09:31 GUI_Tkinter.py*
-rw-r--r-- 1 guowli 1049089  767 Feb 27 15:09 GUI_Tkinter.spec

guowli@5CG450158J MINGW64 /d/Anliven-Running/TempTest
$

guowli@5CG450158J MINGW64 /d/Anliven-Running/TempTest
$ ls -lR
.:
total 8
drwxr-xr-x 1 guowli 1049089    0 Feb 27 15:09 build/
drwxr-xr-x 1 guowli 1049089    0 Feb 27 15:09 dist/
-rwxr-xr-x 1 guowli 1049089 1574 Feb 11 09:31 GUI_Tkinter.py*
-rw-r--r-- 1 guowli 1049089  767 Feb 27 15:09 GUI_Tkinter.spec

./build:
total 4
drwxr-xr-x 1 guowli 1049089 0 Feb 27 15:09 GUI_Tkinter/

./build/GUI_Tkinter:
total 10400
-rw-r--r-- 1 guowli 1049089    1351 Feb 27 15:09 GUI_Tkinter.exe.manifest
-rw-r--r-- 1 guowli 1049089  118100 Feb 27 15:09 out00-Analysis.toc
-rw-r--r-- 1 guowli 1049089   91969 Feb 27 15:09 out00-EXE.toc
-rw-r--r-- 1 guowli 1049089 8490727 Feb 27 15:09 out00-PKG.pkg
-rw-r--r-- 1 guowli 1049089   90661 Feb 27 15:09 out00-PKG.toc
-rw-r--r-- 1 guowli 1049089 1396916 Feb 27 15:09 out00-PYZ.pyz
-rw-r--r-- 1 guowli 1049089   28133 Feb 27 15:09 out00-PYZ.toc
-rw-r--r-- 1 guowli 1049089   80981 Feb 27 15:09 out00-Tree.toc
-rw-r--r-- 1 guowli 1049089    6778 Feb 27 15:09 out01-Tree.toc
-rw-r--r-- 1 guowli 1049089    2866 Feb 27 15:09 warnGUI_Tkinter.txt
-rw-r--r-- 1 guowli 1049089  322575 Feb 27 15:09 xref-GUI_Tkinter.html

./dist:
total 8560
-rwxr-xr-x 1 guowli 1049089 8762599 Feb 27 15:09 GUI_Tkinter.exe*

guowli@5CG450158J MINGW64 /d/Anliven-Running/TempTest
$

運行可執行文件
技術分享圖片

4-2 自定義ico圖標

圖標下載:https://www.easyicon.net/

生成可執行文件

guowli@5CG450158J MINGW64 /d/Anliven-Running/TempTest
$ pyinstaller -F -w -i panda.ico GUI_Tkinter.py
279 INFO: PyInstaller: 3.3.1
279 INFO: Python: 2.7.12
279 INFO: Platform: Windows-7-6.1.7601-SP1
280 INFO: wrote D:\Anliven-Running\TempTest\GUI_Tkinter.spec
......
......
......
13562 INFO: Appending archive to EXE D:\Anliven-Running\TempTest\dist\GUI_Tkinter.exe
13578 INFO: Building EXE from out00-EXE.toc completed successfully.

guowli@5CG450158J MINGW64 /d/Anliven-Running/TempTest
$

guowli@5CG450158J MINGW64 /d/Anliven-Running/TempTest
$ ls -lR
.:
total 76
drwxr-xr-x 1 guowli 1049089     0 Feb 27 15:39 build/
drwxr-xr-x 1 guowli 1049089     0 Feb 27 15:40 dist/
-rwxr-xr-x 1 guowli 1049089  1574 Feb 11 09:31 GUI_Tkinter.py*
-rw-r--r-- 1 guowli 1049089   785 Feb 27 15:39 GUI_Tkinter.spec
-rw-r--r-- 1 guowli 1049089 67646 Feb 27 15:37 panda.ico

./build:
total 4
drwxr-xr-x 1 guowli 1049089 0 Feb 27 15:40 GUI_Tkinter/

./build/GUI_Tkinter:
total 10400
-rw-r--r-- 1 guowli 1049089    1351 Feb 27 15:40 GUI_Tkinter.exe.manifest
-rw-r--r-- 1 guowli 1049089  118100 Feb 27 15:40 out00-Analysis.toc
-rw-r--r-- 1 guowli 1049089   91976 Feb 27 15:40 out00-EXE.toc
-rw-r--r-- 1 guowli 1049089 8490727 Feb 27 15:40 out00-PKG.pkg
-rw-r--r-- 1 guowli 1049089   90661 Feb 27 15:40 out00-PKG.toc
-rw-r--r-- 1 guowli 1049089 1396916 Feb 27 15:40 out00-PYZ.pyz
-rw-r--r-- 1 guowli 1049089   28133 Feb 27 15:40 out00-PYZ.toc
-rw-r--r-- 1 guowli 1049089   80981 Feb 27 15:40 out00-Tree.toc
-rw-r--r-- 1 guowli 1049089    6778 Feb 27 15:40 out01-Tree.toc
-rw-r--r-- 1 guowli 1049089    2866 Feb 27 15:40 warnGUI_Tkinter.txt
-rw-r--r-- 1 guowli 1049089  322575 Feb 27 15:40 xref-GUI_Tkinter.html

./dist:
total 8620
-rwxr-xr-x 1 guowli 1049089 8826599 Feb 27 15:40 GUI_Tkinter.exe*

guowli@5CG450158J MINGW64 /d/Anliven-Running/TempTest
$

運行可執行文件
技術分享圖片

5 - Tips

5-1 onefolder模式

參數:-D, --onedir # 生成一個包含exe文件和依賴文件的目錄
onefolder模式可以用於確認打包是否完整正確。
打包成onefile文件時,發布前最好先打包成onefolder,檢查一下需要的文件是否被正確打包。

5-2 打包IDE編寫的python文件

在類似Pycharm導入的模塊可能並沒有安裝到本地的python環境,就會導致在python文件在PyCharm中能正常運行但在命令行運行報錯的現象。
在使用pyinstaller打包時,對應的現象就是:執行EXE文件閃退,或提示ImportError錯誤。
此問題只需要使用pip安裝相應模塊再打包即可。

5-3 加密python字節碼

利用加密參數 --key ,可自定義一個16位密鑰來加密pyc文件,加大反編譯難度。
註意:必須事先安裝PyCrypto(https://pypi.python.org/pypi/pycrypto/)。
官方文檔:https://pyinstaller.readthedocs.io/en/stable/usage.html#encrypting-python-bytecode
To encrypt the Python bytecode modules stored in the bundle, pass the --key=key-string argument on the command line.
For this to work, you must have the PyCrypto module installed. The key-string is a string of 16 characters which is used to encrypt each file of Python byte-code before it is stored in the archive inside the executable file.

5-4 文件名稱及路徑

  • 文件路徑中不能出現空格和英文句號;
  • 源文件必須是UTF-8編碼,暫不支持其他編碼類型;

5-5 報錯信息

如果執行生成的exe文件閃退,沒有報錯信息,可以嘗試在cmd命令中運行exe文件,可能會看到報錯原因。

5-6 關於跨平臺

雖然Pyinstaller是跨平臺的,但是打包之後的exe文件並不能跨平臺執行。
在Windows系統下打包生成的exe文件只能在Windows系統下運行,同理在Linux下打包生成的exe文件也只能在Linux下運行。
如果將在Windows系統下打包生成的exe文件在Linux下運行,將會報錯“Exec format error. Binary file not executable”。

6 - 幫助信息

-h, --help # 顯示幫助信息

$ pyinstaller -h
usage: pyinstaller [-h] [-v] [-D] [-F] [--specpath DIR] [-n NAME]
                   [--add-data <SRC;DEST or SRC:DEST>]
                   [--add-binary <SRC;DEST or SRC:DEST>] [-p DIR]
                   [--hidden-import MODULENAME]
                   [--additional-hooks-dir HOOKSPATH]
                   [--runtime-hook RUNTIME_HOOKS] [--exclude-module EXCLUDES]
                   [--key KEY] [-d] [-s] [--noupx] [-c] [-w]
                   [-i <FILE.ico or FILE.exe,ID or FILE.icns>]
                   [--version-file FILE] [-m <FILE or XML>] [-r RESOURCE]
                   [--uac-admin] [--uac-uiaccess] [--win-private-assemblies]
                   [--win-no-prefer-redirects]
                   [--osx-bundle-identifier BUNDLE_IDENTIFIER]
                   [--runtime-tmpdir PATH] [--distpath DIR]
                   [--workpath WORKPATH] [-y] [--upx-dir UPX_DIR] [-a]
                   [--clean] [--log-level LEVEL]
                   scriptname [scriptname ...]

positional arguments:
  scriptname            name of scriptfiles to be processed or exactly one
                        .spec-file. If a .spec-file is specified, most options
                        are unnecessary and are ignored.

optional arguments:
  -h, --help            show this help message and exit
  -v, --version         Show program version info and exit.
  --distpath DIR        Where to put the bundled app (default: .\dist)
  --workpath WORKPATH   Where to put all the temporary work files, .log, .pyz
                        and etc. (default: .\build)
  -y, --noconfirm       Replace output directory (default:
                        SPECPATH\dist\SPECNAME) without asking for
                        confirmation
  --upx-dir UPX_DIR     Path to UPX utility (default: search the execution
                        path)
  -a, --ascii           Do not include unicode encoding support (default:
                        included if available)
  --clean               Clean PyInstaller cache and remove temporary files
                        before building.
  --log-level LEVEL     Amount of detail in build-time console messages. LEVEL
                        may be one of TRACE, DEBUG, INFO, WARN, ERROR,
                        CRITICAL (default: INFO).

What to generate:
  -D, --onedir          Create a one-folder bundle containing an executable
                        (default)
  -F, --onefile         Create a one-file bundled executable.
  --specpath DIR        Folder to store the generated spec file (default:
                        current directory)
  -n NAME, --name NAME  Name to assign to the bundled app and spec file
                        (default: first script‘s basename)

What to bundle, where to search:
  --add-data <SRC;DEST or SRC:DEST>
                        Additional non-binary files or folders to be added to
                        the executable. The path separator is platform
                        specific, ``os.pathsep`` (which is ``;`` on Windows
                        and ``:`` on most unix systems) is used. This option
                        can be used multiple times.
  --add-binary <SRC;DEST or SRC:DEST>
                        Additional binary files to be added to the executable.
                        See the ``--add-data`` option for more details. This
                        option can be used multiple times.
  -p DIR, --paths DIR   A path to search for imports (like using PYTHONPATH).
                        Multiple paths are allowed, separated by ‘;‘, or use
                        this option multiple times
  --hidden-import MODULENAME, --hiddenimport MODULENAME
                        Name an import not visible in the code of the
                        script(s). This option can be used multiple times.
  --additional-hooks-dir HOOKSPATH
                        An additional path to search for hooks. This option
                        can be used multiple times.
  --runtime-hook RUNTIME_HOOKS
                        Path to a custom runtime hook file. A runtime hook is
                        code that is bundled with the executable and is
                        executed before any other code or module to set up
                        special features of the runtime environment. This
                        option can be used multiple times.
  --exclude-module EXCLUDES
                        Optional module or package (the Python name, not the
                        path name) that will be ignored (as though it was not
                        found). This option can be used multiple times.
  --key KEY             The key used to encrypt Python bytecode.

How to generate:
  -d, --debug           Tell the bootloader to issue progress messages while
                        initializing and starting the bundled app. Used to
                        diagnose problems with missing imports.
  -s, --strip           Apply a symbol-table strip to the executable and
                        shared libs (not recommended for Windows)
  --noupx               Do not use UPX even if it is available (works
                        differently between Windows and *nix)

Windows and Mac OS X specific options:
  -c, --console, --nowindowed
                        Open a console window for standard i/o (default)
  -w, --windowed, --noconsole
                        Windows and Mac OS X: do not provide a console window
                        for standard i/o. On Mac OS X this also triggers
                        building an OS X .app bundle. This option is ignored
                        in *NIX systems.
  -i <FILE.ico or FILE.exe,ID or FILE.icns>, --icon <FILE.ico or FILE.exe,ID or FILE.icns>
                        FILE.ico: apply that icon to a Windows executable.
                        FILE.exe,ID, extract the icon with ID from an exe.
                        FILE.icns: apply the icon to the .app bundle on Mac OS
                        X

Windows specific options:
  --version-file FILE   add a version resource from FILE to the exe
  -m <FILE or XML>, --manifest <FILE or XML>
                        add manifest FILE or XML to the exe
  -r RESOURCE, --resource RESOURCE
                        Add or update a resource to a Windows executable. The
                        RESOURCE is one to four items,
                        FILE[,TYPE[,NAME[,LANGUAGE]]]. FILE can be a data file
                        or an exe/dll. For data files, at least TYPE and NAME
                        must be specified. LANGUAGE defaults to 0 or may be
                        specified as wildcard * to update all resources of the
                        given TYPE and NAME. For exe/dll files, all resources
                        from FILE will be added/updated to the final
                        executable if TYPE, NAME and LANGUAGE are omitted or
                        specified as wildcard *.This option can be used
                        multiple times.
  --uac-admin           Using this option creates a Manifest which will
                        request elevation upon application restart.
  --uac-uiaccess        Using this option allows an elevated application to
                        work with Remote Desktop.

Windows Side-by-side Assembly searching options (advanced):
  --win-private-assemblies
                        Any Shared Assemblies bundled into the application
                        will be changed into Private Assemblies. This means
                        the exact versions of these assemblies will always be
                        used, and any newer versions installed on user
                        machines at the system level will be ignored.
  --win-no-prefer-redirects
                        While searching for Shared or Private Assemblies to
                        bundle into the application, PyInstaller will prefer
                        not to follow policies that redirect to newer
                        versions, and will try to bundle the exact versions of
                        the assembly.

Mac OS X specific options:
  --osx-bundle-identifier BUNDLE_IDENTIFIER
                        Mac OS X .app bundle identifier is used as the default
                        unique program name for code signing purposes. The
                        usual form is a hierarchical name in reverse DNS
                        notation. For example:
                        com.mycompany.department.appname (default: first
                        script‘s basename)

Rarely used special options:
  --runtime-tmpdir PATH
                        Where to extract libraries and support files in
                        `onefile`-mode. If this option is given, the
                        bootloader will ignore any temp-folder location
                        defined by the run-time OS. The ``_MEIxxxxxx``-folder
                        will be created here. Please use this option only if
                        you know what you are doing.

Python - 使用Pyinstaller將Python代碼生成可執行文件