Package Python and add version information and icons using Pyinstaller 2.1

Source: Internet
Author: User

A small script was recently written with Wxpython, because it wanted to be released to people who did not have Python and Wxpython, and decided to use Pyinstaller 2.1 for packaging.

Several issues were encountered:

1. Add an icon to the packaged file

See Pyinstaller's Operating Manual for easy discovery:

-i <FILE.ico>, -i <FILE.exe,ID>, --icon=<FILE.ico>, --icon=<FILE.exe,ID>
Add an icon to the output executable. Specify an icon FILE. ico to use the that icon. Specify an existing. exe file giving the ID to extract the icon with that ID.

Can be executed at the command line while in use, but it is more recommended to use a bat file to perform

Python pyinstaller.py--icon=targetico_path.ico--onefile--windowed target_py_file.py for packaging

2. Add version information to the packaged program

View Pyinstaller operator's manual found:

--version-file=version_text_file
ADD a Version resource to the. exe output using a version_text_file as produced by Pyi-grab_version.

This means that to add version information you need to specify a version information file, the version information file operation manual also gives the method of production

Capturing Version Data
pyi-grab_version executable_with_version_resource

THE&NBSP;pyi-grab_version  command is invoked with the full path name of a Windows executable that have a Version resource. (A Version resource contains a group of data structures, some containing binary integers and some containing strings, that Describe the properties of the executable. For details see the version information structures page.)

The command writes text that represents a Version resource in readable form. The version text is written to standard output. You can copy it from the console window or redirect it to a file. Then you can edit the version of information to adapt it to your program. This approach was used because version resources is complex. Some elements is optional, others required. When you view the Version tab of a Properties dialog, there's no simple relationship between the data displayed and the St Ructure of the resource. Using pyi-grab_version You can find a executable that displays the kind of information your want, copy its resour Ce data, and modify it to suit your.

The version text file is encoded UTF-8 and may contain non-ascii characters. (Unicode characters is allowed in Version resource string fields.) Be sure to edit and save the text file in UTF-8 unless you is certain it contains only ASCII string values.

The edited version text file can be given with a --version-file= option to pyinstaller or pyi-makesp EC. The text data is converted to a Version resource and installed in the executable output.

In a Version resource there is, 64-bit binary values, fileversion and productversion. In the version text file these is given as four-element tuples, for example:

filevers= (2, 0, 4, 0), prodvers= (2, 0, 4, 0),

The elements of each tuple represent 16-bit values from most-significant to least-significant. For example the fileversion value given resolves to 0002000000040000 in hex.

set_version version_text_file executable_file

The set_version utility reads a version text file as written by Pyi-grab_version, converts it to a versi On resource, and installs this resource in the executable_file specified.

For advanced uses, examine a version text file. You find it's Python code that creates a vsversioninfo object. The class definition for vsversioninfo are found in utils/versioninfo.py in thepyinstaller Dist Ribution folder. You can write a program, the imports that module. In this program you can eval the contents of a version info text file to produce a vsversioninfo object. You can use the . Toraw () method of this object to produce a Version resource in binary form. Or you can apply the Unicode () function to the object to reproduce the version text file.

The above meaning is to use the Pyinstaller built-in grab_ The version.py tool obtains the other. EXE program version information file, the version information file contains the company name, the program internal name version number and so on, and then change the information inside the message to the information you want, and then use the above--version-file= version_text_file parameter to inject the version information into the. exe.

Note that because this version information is strict data structure, so it is best not to open with Notepad, it is possible to invalidate the version information file, I use the notepad++ change, measured useful.

Where grab_version.py is located in the Utils directory under the. \pyinstaller-2.1\utils,pyinstaller 2.1 root directory.

Can be executed at the command line at the time of use, the current path needs to go to the location of the script or the path of the specified grab_version.py, but it is more recommended to use the bat file to execute, only to save the following characters to bat Chinese to grab_ The version.py file goes inside:

Python grab_version.py Targetexe_path

Like what:

Python grab_version.py C:\Windows\System32\diskext.exe

The resulting version information file is in the current directory of the program, and after you change the version information file, you can start using the

Python pyinstaller.py--version-file=file_version_info.txt--icon=ico.ico--onefile--windowed target.py

OK, problem solved.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.