Hub*_*bro 28 python windows pyinstaller
我一直在谷歌上搜索这段时间而没有结果.该PyInstaller手册说:
--version-file=FILE
add a version resource from FILE to the exe
听起来很棒.我想将版本信息放在我的可执行文件中.问题是我不知道"版本文件"是什么样的,我找不到一个我可以使用的例子.我会考虑一个版本文件的例子作为这个问题的可接受的答案.
手册还说:
版本
仅适用于Windows NT系列.版本= 'myversion.txt'.使用GrabVersion.py从可执行文件中窃取版本资源,然后编辑输出以创建自己的版本.(版本资源的语法是如此神秘,我不会尝试从头开始编写.)
我现在尝试使用来自我系统的无数可执行文件.我只是不断收到这些错误:
Traceback (most recent call last):
File "C:\pyinstaller-2.0\utils\GrabVersion.py", line 42, in
vs = versioninfo.decode(sys.argv[1])
File "C:\pyinstaller-2.0\PyInstaller\utils\versioninfo.py", line 33, in decode
nm = win32api.EnumResourceNames(h, RT_VERSION)[0]
IndexError: list index out of range
在没有版本信息的可执行文件上,以及:
Traceback (most recent call last):
File "C:\pyinstaller-2.0\utils\GrabVersion.py", line 43, in
print vs
File "C:\pyinstaller-2.0\PyInstaller\utils\versioninfo.py", line 147, in __repr__
% (indent, self.ffi.__repr__(indent), indent,
File "C:\pyinstaller-2.0\PyInstaller\utils\versioninfo.py", line 251, in __repr__
"filevers=%s," % fv,
TypeError: not all arguments converted during string formatting
其余的.
Aus*_*ips 30
只是快速浏览一下这些消息来源.看来版本文件本身就是Python源本身作为提供的版本文件,可以读取然后再eval编辑.
该GrabVersion.py脚本会显示您已经找到产生错误,所以我修改了__repr__函数FixedFileInfo元组参数手动转换为字符串.
Windows cmd.exe嵌入了Windows版本资源,这里是GrabVersion.py您将保存到文件并输入到PyInstaller的输出.
VSVersionInfo(
ffi=FixedFileInfo(
filevers=(6, 1, 7601, 17514),
prodvers=(6, 1, 7601, 17514),
mask=0x3f,
flags=0x0,
OS=0x40004,
fileType=0x1,
subtype=0x0,
date=(0, 0)
),
kids=[
StringFileInfo(
[
StringTable(
u'040904B0',
[StringStruct(u'CompanyName', u'Microsoft Corporation'),
StringStruct(u'FileDescription', u'Windows Command Processor'),
StringStruct(u'FileVersion', u'6.1.7601.17514 (win7sp1_rtm.101119-1850)'),
StringStruct(u'InternalName', u'cmd'),
StringStruct(u'LegalCopyright', u'\xa9 Microsoft Corporation. All rights reserved.'),
StringStruct(u'OriginalFilename', u'Cmd.Exe'),
StringStruct(u'ProductName', u'Microsoft\xae Windows\xae Operating System'),
StringStruct(u'ProductVersion', u'6.1.7601.17514')])
]),
VarFileInfo([VarStruct(u'Translation', [1033, 1200])])
]
)
Run Code Online (Sandbox Code Playgroud)
我没有尝试使用PyInstaller设置版本资源,所以我不确定这是否有效,我对你的反馈感兴趣.
我可能在以前的答案中缺少此内容,或者也许PyInstaller已被更新,因为最初提供了这些答案,但是PyInstaller的当前文档使用PyInstaller随附的命令行工具为此提供了一种非常简单的方法(尽管我错过了此内容)前几节我查看了文档)。
将此工具指向系统上具有“漂亮”版本信息的.exe文件,它将创建一个人类可读,注释,可编辑的版本资源文件,您可以将其用作起点。
pyi-grab_version executable_with_version_resource
Run Code Online (Sandbox Code Playgroud)
默认情况下,它将文件写入file_version_info.txt工作目录。
在我的svn.exe本地副本上运行以上代码会产生:
# 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, 9, 7, 30920),
prodvers=(1, 9, 7, 30920),
# 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=0x4,
# 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'040904B0',
[StringStruct(u'CompanyName', u'Apache Software Foundation'),
StringStruct(u'FileDescription', u'svn'),
StringStruct(u'FileVersion', u'1.9.7'),
StringStruct(u'InternalName', u'SVN'),
StringStruct(u'LegalCopyright', u'Copyright (c) The Apache Software Foundation'),
StringStruct(u'OriginalFilename', u'svn.exe'),
StringStruct(u'ProductName', u'Subversion'),
StringStruct(u'ProductVersion', u'1.9.7 (r1800392)')])
]),
VarFileInfo([VarStruct(u'Translation', [1033, 1200])])
]
)
Run Code Online (Sandbox Code Playgroud)
根据您的目的对其进行编辑,并将其作为反馈给PyInstaller --version-file,例如
pyinstaller [options] myscript.py --version-file file_version_info.txt
Run Code Online (Sandbox Code Playgroud)
小智 5
使用较早的答案创建版本文件,另存为 version.rc
找到filename.spec文件将其打开。接下来,在该脚本中,找到:
exe = EXE(pyz,...)
Run Code Online (Sandbox Code Playgroud)
在整个部分的末尾添加这段代码,以自动将版本信息嵌入到您的exe文件中
version='version.rc'
Run Code Online (Sandbox Code Playgroud)
保存它,然后再次启动pyinstaller,这次使用以下代码运行安装程序:
pyinstaller filename.spec
Run Code Online (Sandbox Code Playgroud)
这不仅会创建exe文件本身,还将包括所有版本信息。
如果您可能没有考虑过,请filename用程序的文件名替换
我在互联网上找到了一个用于创建版本文件的简单包: https: //pypi.org/project/pyinstaller-versionfile/#description 。根据链接中的信息安装后,应用简单易读的代码就足够了:
\nimport pyinstaller_versionfile\n\npyinstaller_versionfile.create_versionfile(\n output_file="versionfile.txt",\n version="1.2.3.4",\n company_name="My Imaginary Company",\n file_description="Simple App",\n internal_name="Simple App",\n legal_copyright="\xc2\xa9 My Imaginary Company. All rights reserved.",\n original_filename="SimpleApp.exe",\n product_name="Simple App"\n)\nRun Code Online (Sandbox Code Playgroud)\n作为其操作的结果,我们获得一个文件,例如 @mac 的答案。该文件已准备好在 pyinstaller 中使用。
\n| 归档时间: |
|
| 查看次数: |
18043 次 |
| 最近记录: |