利用pyinstaller将py程序打包成exe

机器环境; 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])])
  ]
)

参考链接:

 pyinstaller参数整理

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值