What does a "version file" look like?
Solution 1
Just had a quick look at the sources. It appears that the version file is expected to be Python source itself as the provided version file with be read and then eval
'ed.
The GrabVersion.py
script appears to generate errors as you've already found, so I modified the __repr__
function of FixedFileInfo
to manually convert tuple arguments to strings.
The Windows cmd.exe
has a Windows version resource embedded, here's the output from GrabVersion.py
which you would save to a file and feed to 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])])
]
)
I haven't tried setting a version resource with PyInstaller so I'm not sure if this will work, I'd be interested in your feedback.
Solution 2
I might be missing this in the previous answers, or maybe PyInstaller has been updated since these answers were originally provided, but the current docs for PyInstaller teach a fairly simple method for this using a command-line tool provided with PyInstaller (though I missed this section the first few times I looked to the docs).
Point this tool at an .exe file on your system that has "good looking" version info, and it will create a human-readable, commented, editable version resource file that you can use as a starting point.
pyi-grab_version executable_with_version_resource
which by default writes a file file_version_info.txt
to the working directory.
Running the above on my local copy of svn.exe produces:
# 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])])
]
)
edit this to your purpose, and feed it back to PyInstaller as a --version-file
, e.g.
pyinstaller [options] myscript.py --version-file file_version_info.txt
Solution 3
Create your Version file using an earlier answer save it as version.rc
Locate the filename.spec
file open it.
next in that script, locate the:
exe = EXE(pyz,...)
at the end of that entire section add this piece of code to automatically embed the version information on your exe file
version='version.rc'
Save it and then launch pyinstaller again and this time run the installer using this code:
pyinstaller filename.spec
this will not only create the exe file itself but also include all of your version information as well.
In case you may not have thought about it, replace the filename
with your program's filename
Solution 4
I had problems with Pyinstaller --version-file option in Python 3 and I solve it using Simple Version Resource Tool.
With this tool you can show the content of any version resource, just use the /vo option with any executable file: verpatch.exe /vo c:\Windows\System32\cmd.exe
To add a new version resource to an executable file, just follow this example:
verpatch.exe script.exe 1.0.0.0 /va /pv 1.0.0.0 /s description "Your product description" /s product "Your product name" /s copyright "Your company name, 2016" /s company "Your company name"
Solution 5
I found on the Internet a simple package for creating a version file: https://pypi.org/project/pyinstaller-versionfile/#description . After installing it according to the information from the link, it is enough to apply a simple and readable code:
import pyinstaller_versionfile
pyinstaller_versionfile.create_versionfile(
output_file="versionfile.txt",
version="1.2.3.4",
company_name="My Imaginary Company",
file_description="Simple App",
internal_name="Simple App",
legal_copyright="© My Imaginary Company. All rights reserved.",
original_filename="SimpleApp.exe",
product_name="Simple App"
)
As a result of its operation, we obtain a file, e.g. as in the answer of @mac . The file is ready to use in pyinstaller.
Related videos on Youtube
Comments
-
Hubro almost 2 years
I've been googling this for ages now without results. The PyInstaller manual says:
--version-file=FILE add a version resource from FILE to the exe
That sounds nice. I want to put version information in my executables. The problem is that I have no clue what a "version file" looks like and I can't find a single example of one that I can use. I would consider an example of a version file as an acceptable answer to this question.
What I've tried
The manual also says:
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.)I have attempted this with countless executable files from my system now. I just keep getting these errors:
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
on executables that has no version information, and:
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
On the rest.
-
Hubro over 11 yearsAwesome! That worked perfectly except for one small thing - the "product version" in the resulting executable is blank. It's no big deal for me though.
-
bgmCoder almost 11 yearsFunny, The product version worked fine for me. Make sure you get this line (about the 4th line):
prodvers=(0, 0, 1, 0),
and use commas instead of periods. I don't know what difference it makes, but the product version appears again in the stringtable (about line 24):StringStruct(u'ProductVersion', u'0.0.1.0')])
where periods are used. -
dgrant almost 11 yearsProductVersion is blank for me as well in the .exe.
-
Martin Prikryl about 9 yearsNote that the strings have to be (double) null-terminated, otherwise you might get hideous problems. See also Compiler error when using GetStringFileInfo in InnoSetup on application created with PyInstaller.
-
BuvinJ over 8 yearsSame result here. Everything worked great, except Product Version is blank. Anyone figure this out?
-
BuvinJ over 8 yearsI figured out the ProductVersion issue. It needs to be in the exact same format as as prodvers. You can't use periods, you must use commas, and they must have spaces between them. FileVersion on the other hand can use your own format.
-
Naveen Kumar almost 5 yearsHi I want to add Legal Trademark property how to add?
-
Jossef Harush Kadouri about 4 yearssharing from my experience after testing this tool, it seems to add the information but if you plan to add digital signature afterward with the tool
signtool.exe
thenverpatch.exe
mess things up and causes signature error. the other answer providing--version-file
worked successfully with signtool for me -
jersey bean almost 4 yearsI'm unclear where this VSVersionInfo is located. Do you add this yourself to a version file? How would ever construct this? I'd like to learn more about version files and don't feel this answer was clear enough.
-
Jon Cage over 3 yearsYour link is broken
-
SiL3NC3 about 3 yearsLink updated: pyinstaller.readthedocs.io/en/stable/…