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

原文地址:https://www.cnblogs.com/rfnets/p/3824927.html