linux python 生成可执行文件,比较Python中两个PyInstaller生成的Linux可执行文件

运行pyinstaller时,必须确保执行可重现的构建.即可用于在可执行文件之间执行比特比较的一个.根据docs:

Python uses a random hash to make dicts and other hashed types,and this affects compiled byte-code as well as PyInstaller internal data structures. As a result,two builds may not produce bit-for-bit identical results even when all the components of the application bundle are the same and the two applications execute in identical ways.

为此,只需在运行pyinstaller之前将PYTHONHASHSEED环境变量设置为常量:

PYTHONHASHSEED=1

export PYTHONHASHSEED

pyinstaller --onefile test.py

unset PYTHONHASHSEED

然后你可以使用你想要比较可执行文件的任何工具/模块,比如filecmp,BeyondCompare等,甚至只是Linux中的一个简单校验和:

cksum dist/test

编辑:关于时间戳或标记二进制文件 – 您可以执行以下操作以在构建后为Linux二进制文件添加其他注释:

# Create a file with the notes or comments to add to the binary.

# I am adding the current date for versioning info

date > version

# Add notes to the binary

objcopy --add-section .pyversion=version --set-section-flags .pyversion=noload,readonly dist/test dist/test-with-version

# Check the version/notes on the new binary

objdump -sj .pyversion dist/test-with-version

你应该得到类似的东西:

dist/test-with-version: file format elf64-x86-64

Contents of section .pyversion:

0000 46726920 53657020 31342031 343a3339 Fri Sep 14 14:39

0010 3a333620 41455354 20323031 380a :36 AEST 2018.

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值