Pyinstaller打包程序为*.exe

今天听说一同事用cx_freeze将PyQt5打包成功,很是惊奇,回来自己试了用Pyinstaller打包,成功

 

1.安装pyinstaller

Python2.6+直接使用pip install pyinstaller安装即可

因为我用的是Python3.4,所以只好到github上下支持3.x的版本

https://github.com/pyinstaller/pyinstaller/tree/python3

2.自己随便用PyQt5编写一个简易浏览器

 

3.开始打包

>pyinstaller -F -w -p G:\pro\ceshidabao\ui -p G:\pro\ceshidabao\util -i G:\pro\ceshidabao\ui\img\fav.ico setup.py

 

pyinstaller还提供其他的一些选项:
-F, --onefile produce a single file deployment (see below).
-D, --onedir produce a single directory deployment (default).
-K, --tk include TCL/TK in the deployment.
-a, --ascii do not include encodings. The default (on Python versions with unicodesupport) is now to include all encodings.
-d, --debug use debug (verbose) versions of the executables.
-w, --windowed, --noconsole
Use the Windows subsystem executable, which does not openthe console when the program is launched.(Windows only)
-c, --nowindowed, --console
Use the console subsystem executable. This is the default. (Windows only)
-s, --strip the executable and all shared libraries will be run through strip. Notethat cygwin's strip tends to render normal Win32 dlls unusable.
-X, --upx if you have UPX installed (detected by Configure), this will use it tocompress your executable (and, on Windows, your dlls). See note below.
-o DIR,--out=DIR
create the spec file in directory. If not specified, and the currentdirectory is Installer's root directory, an output subdirectory will becreated. Otherwise the current directory is used.
-p DIR,--paths=DIR
set base path for import (like using PYTHONPATH). Multiple directories areallowed, separating them with the path separator (';' under Windows, ':'under Linux), or using this option multiple times.
--icon=<FILE.ICO>
add file.ico to the executable's resources. (Windows only)
--icon=<FILE.EXE,N>
add the n-th incon in file.exe to the executable's resources.(Windowsonly)
-v FILE,--version=FILE
add verfile as a version resource to the executable. (Windows only)
-n NAME,--name=NAME
optional name to assign to the project (from which the spec file name isgenerated). If omitted, the basename of the (first) script is used.

 

4.查看效果

结果还不错,

可能很多没用的包都打进去了,所以比较大,实际项目中这是不行的,还要好好优化。

posted @ 2015-08-26 00:37  爱在夕阳下  阅读(1536)  评论(0编辑  收藏  举报