码迷,mamicode.com
首页 > 编程语言 > 详细

python程序打包成.exe----pyinstaller工具

时间:2015-10-22 17:17:03      阅读:653      评论:0      收藏:0      [点我收藏+]

标签:

1. 环境

windows

 

2. 安装

准备文件:PyWin32 or pypiwin32 

运行如下安装命令:  pip install pyinstaller

 

3. 打包

把.py或.pyw文件拷贝到pyinstaller所在目录

执行命令: pyinstaller -F xxx.py ,会把生成的文件自动放到dist目录下,文件名默认为xxx.exe。

常用参数说明:

-F:把所有文件打包成一个.exe。

-D:把所有文件打包成一个目录,里面包含可执行文件和所需库等其他文件。

-n NAME:重新命名可执行文件。

-w:打开打包后的程序,将不会弹出命令行窗口。

 

4. 单独文件和目录比较

目录的比单个文件尺寸要大;

目录的比单个文件打开速度要快。

在WIN7上打包,放到XP上,目录的打开失败,单个文件正常。

 

详细参数说明见文档

http://pythonhosted.org/PyInstaller/#general-options

General Options

-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=LOGLEVEL
  Amount of detail in build-time console messages (default: INFO, choose one of DEBUG, INFO, WARN, ERROR, CRITICAL)

What to generate

-F, --onefile Create a one-file bundled executable.
-D, --onedir Create a one-folder bundle containing an executable (default)
--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)

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 <FILE[,TYPE[,NAME[,LANGUAGE]]]>--resource=<FILE[,TYPE[,NAME[,LANGUAGE]]]>
  Add or update a resource of the given type, name and language from FILE to a Windows executable. 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.

python程序打包成.exe----pyinstaller工具

标签:

原文地址:http://www.cnblogs.com/testlife007/p/4901507.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!