python 打包总结
一、配置:
python 3.7.4
pyinstaller 4.9
二、win打包
pyinstaller -F example.py
exe会自动生成到dist文件夹
三、mac打包
pyinstaller -F example.py
签名
codesign --entitlements=example.entitlements --deep --force --verbose --timestamp --options=runtime --sign "证书名称" "要签名的文件"
<?xml version="1.0" encoding="utf-8"?>
<plist version="1.0">
<dict>
<key>com.apple.security.automation.apple-events</key>
<true/>
<key>com.apple.security.files.user-selected.read-write</key>
<true/>
<key>com.apple.security.cs.allow-jit</key>
<true/>
<key>com.apple.security.cs.allow-unsigned-executable-memory</key>
<true/>
<key>com.apple.security.cs.allow-dyld-environment-variables</key>
<true/>
<key>com.apple.security.cs.disable-executable-page-protection</key>
<true/>
<key>com.apple.security.cs.disable-library-validation</key>
<true/>
</dict>
</plist>
上面的com.apple.security.cs.disable-library-validation千万不能少,因为pyinstaller会把python打包到可执行文件,运行时再解压启动,所以这里的python是签不到名的,所以必须关闭库验证
扩展:
查看 授权机制 entitements信息
codesign -d --entitlements - <可执行文件或.app>
添加版本信息
pyinstaller添加版本信息只有win能用
需要特定的格式,可以通过pyi-grab_version获取,这个是Pyinstaller自带的,下面给个例子吧
version_template.pen
# 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=(1, 0, 0, 1),
prodvers=(1, 0, 0, 1),
# 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=0x2,
# 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(
'080404b0',
[StringStruct('CompanyName', '公司名称'),
StringStruct('FileDescription', '文件描述'),
StringStruct('FileVersion', '1.0.0,$GIT_VER'),
StringStruct('InternalName', '文件名'),
StringStruct('LegalCopyright', '版权信息'),
StringStruct('OriginalFilename', '文件名'),
StringStruct('ProductName', '产品名'),
StringStruct('ProductVersion', '1.0.0,$GIT_VER')])
]),
VarFileInfo([VarStruct('Translation', [2052, 1200])])
]
)
pyinstaller -F example.py --version-file=version_template.pen