pyinstaller参数
-F, –onefile
# 打包一个单个文件,如果你的代码都写在一个.py文件的话,可以用这个,如果是多个.py文件就别用
-D, –onedir
# 打包多个文件,在dist中生成很多依赖文件,适合以框架形式编写工具代码,我个人比较推荐这样,代码易于维护
-K, –tk
# 在部署时包含 TCL/TK
-a, –ascii
# 不包含编码.在支持Unicode的python版本上默认包含所有的编码.
-d, –debug
# 产生debug版本的可执行文件
-w,–windowed,–noconsole
# 使用Windows子系统执行.当程序启动的时候不会打开命令行(只对Windows有效)
-c,–nowindowed,–console
# 使用控制台子系统执行(默认)(只对Windows有效)
pyinstaller -c xxxx.py
pyinstaller xxxx.py --console
-s,–strip
# 可执行文件和共享库将run through strip.注意Cygwin的strip往往使普通的win32 Dll无法使用.
-X, –upx
# 如果有UPX安装(执行Configure.py时检测),会压缩执行文件(Windows系统中的DLL也会)(参见note)
-o DIR, –out=DIR
# 指定spec文件的生成目录,如果没有指定,而且当前目录是PyInstaller的根目录,会自动创建一个用于输出(spec和生成的可执行文件)的目录.如果没有指定,而当前目录不是PyInstaller的根目录,则会输出到当前的目录下.
-p DIR, –path=DIR
# 设置导入路径(和使用PYTHONPATH效果相似).可以用路径分割符(Windows使用分号,Linux使用冒号)分割,指定多个目录.也可以使用多个-p参数来设置多个导入路径,让pyinstaller自己去找程序需要的资源
–icon=<FILE.ICO>
# 将file.ico添加为可执行文件的资源(只对Windows系统有效),改变程序的图标 pyinstaller -i ico路径 xxxxx.py
–icon=<FILE.EXE,N>
# 将file.exe的第n个图标添加为可执行文件的资源(只对Windows系统有效)
-v FILE, –version=FILE,--version-file
# 将verfile作为可执行文件的版本资源(只对Windows系统有效)
-n NAME, –name=NAME
# 可选的项目(产生的spec的)名字.如果省略,第一个脚本的主文件名将作为spec的名字
MacOS 打包
pip install -i http://mirrors.aliyun.com/pypi/simple --trusted-host mirrors.aliyun.com virtualenv
virtualenv --no-site-packages venv # pyinstaller 对virtualenv兼容性更好
# 纯净的python环境
source venv/bin/activate
# 加入env环境
pip install -i http://mirrors.aliyun.com/pypi/simple --trusted-host mirrors.aliyun.com pyqt5 pyinstaller
pip install -i http://mirrors.aliyun.com/pypi/simple --trusted-host mirrors.aliyun.com scapy
# 第三方包
pyinstaller --windowed --onefile --clean --noconfirm main.py
# pyinstaller --windowed --onefile --icon=tool.icns --clean --noconfirm main.py # Mac图标文件
pyinstaller --clean --noconfirm --windowed --onefile main.spec
# 最终打包程序
windows打包
virtualenv venv
venv\Scripts\activate
pip install -i http://mirrors.aliyun.com/pypi/simple --trusted-host mirrors.aliyun.com pyqt5 pyinstaller
pyinstaller -i=".\tool.ico" -Fw main.py
# 打包程序
版本信息设置
~/.pyenv/versions/3.6.8/lib/python3.6/site-packages/PyInstaller/utils/cliutils
#-----------------------------------------------------------------------------
# Copyright (c) 2013-2020, PyInstaller Development Team.
#
# Distributed under the terms of the GNU General Public License (version 2
# or later) with exception for distributing the bootloader.
#
# The full license is in the file COPYING.txt, distributed with this software.
#
# SPDX-License-Identifier: (GPL-2.0-or-later WITH Bootloader-exception)
#-----------------------------------------------------------------------------
import codecs
import argparse
def run():
parser = argparse.ArgumentParser(
epilog = ('The printed output may be saved to a file, edited and '
'used as the input for a version resource on any of the '
'executable targets in an Installer spec file.'))
parser.add_argument('exe_file', metavar='exe-file',
help="full pathname of a Windows executable")
parser.add_argument('out_filename', metavar='out-filename', nargs='?',
default='file_version_info.txt',
help=("filename where the grabbed version info "
"will be saved"))
args = parser.parse_args()
try:
import PyInstaller.utils.win32.versioninfo
vs = PyInstaller.utils.win32.versioninfo.decode(args.exe_file)
if not vs:
raise SystemExit("Error: VersionInfo resource not found in exe")
with codecs.open(args.out_filename, 'w', 'utf-8') as fp:
fp.write(u"%s" % (vs,))
print(('Version info written to: %s' % args.out_filename))
except KeyboardInterrupt:
raise SystemExit("Aborted by user request.")
if __name__ == '__main__':
run()
用于获得其他程序的版本信息文件
grab_version.py xxx.exe
# 生产文件
pyinstaller -i=".\tool.ico" --version-file=".\file_version_info.txt" -Fw main.py
# 打包文件