我已经用谷歌搜索了好几年都没有结果了。手册上说:
--version-file=FILE add a version resource from FILE to the exe
听起来不错。我想把版本信息放到我的可执行文件中。问题是我不知道“版本文件”是什么样子的,我找不到一个可以使用的例子。我会考虑一个版本文件的例子作为这个问题的一个可接受的答案。
手册还说:
version
Windows NT family only. version='myversion.txt'. Use GrabVersion.py to steal a version resource from an executable, and then edit the ouput to create your own. (The syntax of version resources is so arcane that I wouldn't attempt to write one from scratch.)
我已经尝试了无数的可执行文件从我的系统现在。我只是不断地犯这些错误:
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
其余的。
只是简单地看了一下资料来源。似乎版本文件应该是Python源代码本身,作为提供的版本文件,先读取,然后
eval
GrabVersion.py
脚本似乎会生成您已经发现的错误,因此我修改了FixedFileInfo
的__repr__
函数,将元组参数手动转换为字符串。Windows
cmd.exe
嵌入了一个Windows版本资源,这是GrabVersion.py
的输出,您可以将其保存到文件并馈送到PyInstaller。我还没有尝试用PyInstaller设置版本资源,所以我不确定这是否有效,我会对你的反馈感兴趣。
我可能在前面的答案中遗漏了这一点,或者PyInstaller在最初提供这些答案之后已经更新了,但是PyInstaller的当前文档使用PyInstaller提供的命令行工具来教一个fairly simple method for this(尽管我在最初几次查看文档时遗漏了这一部分)。
将此工具指向系统上具有“好看的”版本信息的.exe文件,它将创建一个可读的、带注释的、可编辑的版本资源文件,您可以将其用作起点。
默认情况下,它会将文件
file_version_info.txt
写入工作目录。在svn.exe的本地副本上运行上述命令将生成:
根据您的需要进行编辑,并将其作为
--version-file
反馈给PyInstaller,例如使用前面的答案创建版本文件另存为
version.rc
找到
filename.spec
文件,打开它。 接下来,在该脚本中,找到:在整个部分的末尾添加这段代码,以自动将版本信息嵌入到您的exe文件中
保存它,然后再次启动pyinstaller,这次使用以下代码运行安装程序:
这不仅会创建exe文件本身,还包括所有的版本信息。
如果您可能没有想过,请用程序的文件名替换
filename
相关问题 更多 >
编程相关推荐