最近用 wxpython写了一个小的脚本,因为想要发布给没有装python和wxpython的人使用,遂决定使用pyinstaller 2.1进行打包。

其中遇到几个问题:

1,给打包的文件添加图标

  查看pyinstaller 的操作手册很容易发现:

-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 that icon. Specify an existing .exe file giving the ID to extract the icon with that ID.

  可以在使用的时候,在命令行中执行,不过更推荐的是使用bat文件来执行

  python pyinstaller.py --icon=targetico_path.ico--onefile   --windowed target_py_file.py进行打包

2,给打包的程序添加版本信息

  查看pyinstaller 操作手册发现:

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

  也就是说要添加版本信息需要指定一个版本信息文件,版本信息文件操作手册中也给了制作方法

Capturing Version Data

pyi-grab_version executable_with_version_resource

The pyi-grab_version command is invoked with the full path name of a Windows executable that has 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 information to adapt it to your program. This approach is used because version resources are complex. Some elements are optional, others required. When you view the version tab of a Properties dialog, there's no simple relationship between the data displayed and the structure of the resource. Using pyi-grab_version you can find an executable that displays the kind of information you want, copy its resource data, and modify it to suit your package.

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

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

In a Version resource there are two 64-bit binary values, FileVersion and ProductVersion. In the version text file these are 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 Version resource, and installs that resource in the executable_file specified.

For advanced uses, examine a version text file. You find it is Python code that creates a VSVersionInfo object. The class definition for VSVersionInfo is found in utils/versioninfo.py in thePyInstaller distribution folder. You can write a program that imports that module. In that program you can eval the contents of a version info text file to produce a VSVersionInfo object. You can use the .toRaw() method of that 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.

  上面的意思呢就是使用pyinstaller内置的grab_version.py工具获得其他.exe程序的版本信息文件,版本信息文件里面包括公司名,程序内部名称版本号之类,然后再把这个信息里面的相关信息更改成你想要的信息,再使用上面的--version-file=version_text_file 参数的把版本信息注射到.exe中去。

  其中注意因为这个版本信息是严格的数据结构,所以最好不要用notepad打开,有可能导致版本信息文件失效,我用的是notepad++更改,实测有用。

  其中grab_version.py的位置在.\PyInstaller-2.1\utils,pyinstaller 2.1根目录下的utils目录下。

  可以在使用的时候,在命令行中执行,需要将当前路径转到该脚本所在地或者指定grab_version.py的路径,不过更推荐的是使用bat文件来执行,只需要将下面字符保存到bat中方到grab_version.py文件里面去了:

  python grab_version.py targetExe_path

  比如:

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

  产生的版本信息文件就在程序的当前目录下,更改好版本信息文件之后就可以开始使用了 

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

  OK,问题解决。

使用pyinstaller 2.1将python打包并添加版本信息和图标的更多相关文章

  1. python基础之获取版本信息

    在工作中经常会需要确定使用的py的版本信息,以便适配更多的系统,达到更大的兼容性. 一般关于python的信息和参数都要调用sys模块,关于操作系统的信息和调用都要使用os模块 所以这次我们使用sys ...

  2. Python 调用接口添加头信息

    import requests,jsonurl = 'http://47.108.115.193:9000/tb-store/store/getWechatAppHome'header={" ...

  3. webpack 打包增加版本信息

    What do we need? 笔者目的是在vue项目打包后的 dist/index.html 文件中写入本次打包git用户.最后一次git提交信息,这样做的目的是便于线上项目的管理和防止同事之间的 ...

  4. Python打包—Pyinstaller

    2018-09-27 21:12:05   一 前言 在windows平台学习python的过程中,你肯定会遇到需要把.py脚本打包成.exe的情形,如此,至少有两方面的好处:第一,你的代码保密性更好 ...

  5. python打包工具pyinstaller的使用

    安装PyInstaller pip install pyinstaller 安装完后,检查安装成功与否: pyinstaller --version 安装成功后,就可以使用下面的命令了: pyinst ...

  6. $python打包工具pyinstaller的用法

    pyinstaller是一个很好用的python打包工具,在Windows环境下可以将python脚本打包成一个exe可执行文件,并且脚本中所依赖的各种第三方库在打包时候都会被统一处理到一起,这样打包 ...

  7. 使用pyinstaller将Python打包为exe文件

    当我们完成一个Python项目或一个程序时,希望将Python的py文件打包成在Windows系统下直接可以运行的exe程序,那么pyInstaller就是一个很好的选择.pyInstaller可以将 ...

  8. python打包exe之pyinstaller用法

    pyinstaller可以将python写好的脚本打包成exe文件,方便windows用户在没有python环境下运行.这个程序完全跨平台,包括Windows.Linux.Mac OS X等多个操作系 ...

  9. py库:把python打包成exe文件(pyinstaller)

    http://blog.csdn.net/be_quiet_endeavor/article/details/73929077 用Pyinstaller把Python3.4程序打包成可执行文件exe ...

随机推荐

  1. Maven配置 settings.xml 转

    https://my.oschina.net/qjx1208/blog/201085 摘要: 记录settings.xml的配置,理解mirror.repository.profile的关系 本地仓库 ...

  2. java读取配置文件

    java 读取文件可以用字节流和字符流. 由于一个汉字占两个字节,所以如果配置文件中有汉字,用字节流读取,会出现乱码. 用字符流则不会出现乱码. 配置文件 b.properties 文件如下: fam ...

  3. 非常实用的PHP常用函数汇总

    这篇文章主要介绍了非常实用的PHP常用函数,汇总了加密解密.字符串操作.文件操作.SQL注入等函数的实例与用法说明,在PHP项目开发中非常具有实用价值,需要的朋友可以参考下 本文实例总结了一些在php ...

  4. 什么是jetty

    转自:http://www.cnblogs.com/eafy/archive/2007/10/24/906792.html 1. 简介 Jetty 是一个开源的servlet容器,它为基于Java的w ...

  5. 在VS Nuget命令行下进行EF数据库迁移

    找到项目中,用到数据库DLL的地方,然后选中该项目,打开Nuget命令行输入以下的命令: 其中cardId为迁移名称,自己取

  6. C# winform如何在textbox中判断输入的是字母还是数字?

    1.用正规式using System.Text.RegularExpressions; string pattern = @"^\d+(\.\d)?$";if(Text1.Text ...

  7. JAVA向文件中追加内容(转)

    向文件尾加入内容有多种方法,常见的方法有两种: RandomAccessFile类可以实现随机访问文件的功能,可以以读写方式打开文件夹的输出流 public void seek(long pos)可以 ...

  8. TCP/IP 编程

    http://www.cnblogs.com/ggjucheng/archive/2012/08/18/2645324.html

  9. python学习笔记--easy_install和pip

    "A tool for installing and managing Python packages"     --pip easy_insall和pip都提供了在线一键安装模块 ...

  10. Linux学习笔记总结--CentOS 设置静态IP

    1.修改网卡配置 vi /etc/sysconfig/network-scripts/ifcfg-eth0 DEVICE=eth0 #描述网卡对应的设备别名,例如ifcfg-eth0的文件中它为eth ...