- 1 year ago
Set Product Version Number metadata on .exe file with PyInstaller
To set the Product Version Number metadata on an .exe
file generated with PyInstaller, you can use the --version-file
option to specify a version resource file that contains the desired metadata. Here's how you can do it:
Create a version resource file:
Create a text file (e.g.,
version.rc
) and add the following content:sqlVS_VERSION_INFO VERSIONINFO
FILEVERSION 1,0,0,0
PRODUCTVERSION 1,0,0,0
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
#else
FILEFLAGS 0x0L
#endif
FILEOS 0x4L
FILETYPE 0x1L
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904b0"
BEGIN
VALUE "FileVersion", "1, 0, 0, 0"
VALUE "ProductVersion", "1, 0, 0, 0"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x409, 1200
END
END
Modify the
FILEVERSION
andPRODUCTVERSION
fields with the desired version numbers.
Use PyInstaller with the
--version-file
option:Open a command prompt or terminal.
Navigate to the directory where your PyInstaller script is located.
Run the following command to generate the executable with the version metadata:
csspyinstaller your_script.py --version-file version.rc
Replace
your_script.py
with the name of your PyInstaller script, andversion.rc
with the path to the version resource file you created.PyInstaller will generate the
.exe
file with the specified version number metadata.
The version metadata you set in the version resource file will be visible when viewing the properties of the generated .exe
file in Windows. Note that this metadata does not affect the internal versioning within your Python script itself.
By using the --version-file
option with PyInstaller and providing a version resource file, you can set the Product Version Number metadata on the resulting .exe
file.