pyinstaller官方網頁:http://www.pyinstaller.org/
官方文檔:https://pyinstaller.readthedocs.io/en/stable/
pyinstaller支持Python 2.7和Python 3.3+版本,並且支持Windows(XP+)、Mac OS X(10.7+)和Linux,但是只能在對應的系統編譯對應的程序。
1、pyinstaller安裝
在cmd(命令提示符)中直接安裝
1 pip install pyinstaller
等待pip自動下載pyinstaller、pefile、pypiwin32、future共四個文件並自動安裝,安裝完成后輸入
1 pyinstaller
會輸出pyinstaller的使用方法如下:
1 usage: pyinstaller-script.py [-h] [-v] [-D] [-F] [--specpath DIR] [-n NAME] 2 [-p DIR] [--hidden-import MODULENAME] 3 [--additional-hooks-dir HOOKSPATH] 4 [--runtime-hook RUNTIME_HOOKS] 5 [--exclude-module EXCLUDES] [--key KEY] [-d] [-s] 6 [--noupx] [-c] [-w] 7 [-i <FILE.ico or FILE.exe,ID or FILE.icns>] 8 [--version-file FILE] [-m <FILE or XML>] 9 [-r RESOURCE] [--uac-admin] [--uac-uiaccess] 10 [--win-private-assemblies] 11 [--win-no-prefer-redirects] 12 [--osx-bundle-identifier BUNDLE_IDENTIFIER] 13 [--distpath DIR] [--workpath WORKPATH] [-y] 14 [--upx-dir UPX_DIR] [-a] [--clean] 15 [--log-level LEVEL] [--upx UPX] 16 scriptname [scriptname ...] 17 pyinstaller-script.py: error: the following arguments are required: scriptname
2、pyinstaller使用
直接在CMD中輸入命令:
1 pyinstaller -F -w E:\Programer\Python\scraping\demo3.py
在經過一系列的信息和警告輸出后完成,會提示出生成的exe文件存放在哪兒。
找到目錄C:\Windows\system32\dist\文件夾(可能也在C:\Windows\SysWOW64\dist\文件里,估計和Python 32bit/64bit有關),即可運行生成的exe文件
[options]
-F 生成一個exe單文件
-D 生成一個文件夾(默認選項)