pyinstaller 用法


參考:http://pythonhosted.org/PyInstaller/#installing-pyinstaller

1、下載pyinstaller和PyWin32 

目前pyinstaller支持的python版本為2.3-2.7,可以到http://www.pyinstaller.org/官網下載。注意PyWin32 對應不太的python版本

2、安裝

pyinstaller下載完成后,解壓即可。PyWin32 安裝

3、pyinstaller使用方法

使用也非常的簡單,cmd下進入解壓出來的目錄,進入當前目錄,比方說解壓到d:/pyinstaller/,執行

方法一:當前目錄下沒有spec文件,執行
python pyinstaller.py [opts] yourprogram.py
  • 方括號[]里面為可選項,
  • 執行目錄后,在d:/pyinstaller/目錄里面生成一個your-program/dist子目錄,你有用的文件就放在這里了,
  • 同時生成一個your-program/your-program.spec文件
  • 同時生成一個your-program/build,里面存放buid文件(中間件)
  • 如果程序不在“d:/pyinstaller/”里面,指定程序的路徑,spec,dist,buid目錄文件將在當前目錄下生成
方法一:當前目錄下有spec文件,執行
python pyinstaller.py [opts] your-program.spec

4 主要選項包括:

Allowed OPTIONS are:
-h, --help show this help message and exit
-v, --version show program version
--upx-dir=UPX_DIR Directory containing UPX.
-a, --ascii do NOT include unicode encodings (default:
included if available)
--buildpath=BUILDPATH Buildpath (default:
SPECPATH/build/pyi.TARGET_PLATFORM/SPECNAME)

-y, --noconfirm Remove output directory (default:
SPECPATH/dist/SPECNAME) without
confirmation
--log-level=LOGLEVEL Log level (default: INFO, choose one of DEBUG,
INFO, WARN, ERROR, CRITICAL

What to generate:

-F, --onefile create a single file deployment

-D, --onedir create a single directory deployment (default)
-o DIR, --out=DIR create the spec file in directory. If not specified,
and the current directory is Installer's root
directory, an output subdirectory will be created.
Otherwise the current directory is used.
-n NAME, --name=NAME optional name to assign to the project (from which
          the spec file name is generated). If omitted, the
basename of the (first) script is used.

 

-F, –onefile 打包成一個exe文件。
-D, –onedir 創建一個目錄,包含exe文件,但會依賴很多文件(默認選項)。
-c, –console, –nowindowed 使用控制台,無界面(默認)
-w, –windowed, –noconsole 使用窗口,無控制台

具體參考PyInstaller安裝目錄下的PyInstaller Manual


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM