使用pyinstaller將python文件打包成exe文件

pyinstaller官方網頁:http://www.pyinstaller.org/api

官方文檔:https://pyinstaller.readthedocs.io/en/stable/ide

pyinstaller支持Python 2.7和Python 3.3+版本,而且支持Windows(XP+)、Mac OS X(10.7+)和Linux,可是隻能在對應的系統編譯對應的程序。ui

 

一、pyinstaller安裝spa

在cmd(命令提示符)中直接安裝code

1 pip install pyinstaller

等待pip自動下載pyinstaller、pefile、pypiwin3二、future共四個文件並自動安裝,安裝完成後輸入blog

1 pyinstaller

會輸出pyinstaller的使用方法以下:ip

 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

 

二、pyinstaller使用文檔

直接在CMD中輸入命令:get

1 pyinstaller -F -w E:\Programer\Python\scraping\demo3.py

在通過一系列的信息和警告輸出後完成,會提示出生成的exe文件存放在哪兒。
cmd

找到目錄C:\Windows\system32\dist\文件夾(可能也在C:\Windows\SysWOW64\dist\文件裏,估計和Python 32bit/64bit有關),便可運行生成的exe文件

[options]

-F  生成一個exe單文件

-D  生成一個文件夾(默認選項)

相關文章
相關標籤/搜索