机器环境; Python2.7 + Python 3.6
需求:需要将python2代码打包成exe格式
第一次尝试:
pip install pyinstaller
pyinstaller -F 文件名.py
-F, –onefile 打包为单个文件
问题:默认为python3。运行失败、
第二次尝试:
首先卸载pyinstaller,之后
pip2 install pyinstaller
报错。
解决方案:
去pypi下载老版本支持python2的pyinstaller,本地安装。成功。
最终命令:
pyinstaller -F -i ./logo.ico --version-file version.txt filename.
py
-i : 后加ico路径,为文件增加图标
--version-file: 后加配置信息
格式如:
# UTF-8
#
# For more details about fixed file info 'ffi' see:
# http://msdn.microsoft.com/en-us/library/ms646997.aspx
VSVersionInfo(
ffi=FixedFileInfo(
# filevers and prodvers should be always a tuple with four items: (1, 2, 3, 4)
# Set not needed items to zero 0.
filevers=(9, 3, 3, 27011),
prodvers=(9, 3, 3, 27011),
# Contains a bitmask that specifies the valid bits 'flags'r
mask=0x3f,
# Contains a bitmask that specifies the Boolean attributes of the file.
flags=0x0,
# The operating system for which this file was designed.
# 0x4 - NT and there is no need to change it.
OS=0x40004,
# The general type of file.
# 0x1 - the file is an application.
fileType=0x1,
# The function of the file.
# 0x0 - the function is not defined for this fileType
subtype=0x0,
# Creation date and time stamp.
date=(0, 0)
),
kids=[
StringFileInfo(
[
StringTable(
u'080404b0',
[StringStruct(u'CompanyName', u'Initial_T'),
StringStruct(u'FileDescription', u'描述'),
StringStruct(u'FileVersion', u'2021.2'),
StringStruct(u'LegalCopyright', u'Copyright (C) Initial_T'),
StringStruct(u'ProductName', u'程序名'),
StringStruct(u'ProductVersion', u'2021.2')])
]),
VarFileInfo([VarStruct(u'Translation', [2052, 1200])])
]
)
参考链接: