使用PyInstaller生成EXE文件
有多款软件可以实现将python转译成exe执行文件
方便将程序分享给没有安装python环境或者不能安装类库的情况
py2exe,cx_Freeze,PyInstaller
目前貌似只有cx_Freeze能实现对于python3.*的转译,但转译过程还有很多的问题,如:中文!!!!
py2exe很久没更新了,那日后转译3.*的可能性很低
pyInstaller还是很活跃的,现在在制作3,不知道是否能支持python3.*,但还有希望
所以还是使用pyInstaller来作为使用目标
1.首先进入官网下载:http://www.pyinstaller.org/
将pyinstaller放入项目目录下,方便调用
2.安装后执行pyinstaller.py
提示python2.6+需要安装pywin32:http://sourceforge.net/projects/pywin32/
需要下载对应自己本机python的版本
3.查看命令:
Usage: pyinstaller.py [opts] <scriptname> [ <scriptname> ...] | <specfile>
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:
D:\PyInstaller-2.1\dist)
--workpath=WORKPATH Where to put all the temporary work files, .log, .pyz
and etc. (default: D:\PyInstaller-2.1\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)
What to bundle, where to search:
-p DIR, --paths=DIR
A path to search for imports (like using PYTHONPATH).
Multiple paths are allowed, separated by ';', or use
this option multiple times
--hidden-import=MODULENAME
Name an import not visible in the code of the
script(s). This option can be used multiple times.
--additional-hooks-dir=HOOKSPATH
An additional path to search for hooks. This option
can be used multiple times.
--runtime-hook=RUNTIME_HOOKS
Path to a custom runtime hook file. A runtime hook is
code that is bundled with the executable and is
executed before any other code or module to set up
special features of the runtime environment. This
option can be used multiple times.
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 F
ILE.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.
Obsolete options (not used anymore):
-X, -K, -C, -o, --upx, --tk, --configfile, --skip-configure, --out, --buildpath
These options do not exist anymore.
常用命令:
#生成一个窗体exe文件在当前目录下的dist目录
pyinstaller.py -F -w main.py