一、实验环境

1.Windows7x64_SP1

2.anaconda2.5.0 + python2.7(anaconda集成,不需单独安装)

3.pyinstaller3.0

python2.7使用最新3.5存在问题,使用最新3.5存在问题,使用最新3.5存在问题,重要的事情说三遍!

安装最新的pyinstaller3.5,打包运行正常,但运行程序报错,弹出对话框提示Fatal Error,做如下debug:

1.使用管理员权限运行cmd,输入如下命令

pyinstaller -D smartbit_tool.py -w -i .\ico\magnifier.ico

运行程序依然报错,弹出对话框提示Fatal Error,看来不是cmd权限不够问题

2.pyinstaller打包参数中打开控制台,命令如下

pyinstaller -D smartbit_tool.py -i .\ico\magnifier.ico

运行程序依然报错,弹出的控制台一闪而过,无法看清具体出错信息

在批处理中执行如上程序,终于看到报错信息,提示pyinstaller未找到sip模块,Google后发现pyinstaller会调用sip模块,非个人编写的程序代码。

于是卸载pyinstaller3.5,重新安装pyinstaller3.0,打包程序,程序运行正常。

二、实验步骤

2.1 pyinstaller帮助手册 ,可以使用如下命令查看

pyinstaller -h

帮助文档如下:

Usage: pyinstaller [opts] <scriptname> [ <scriptname> ...] | <specfile>

Options:
-h, --help show this help message and exit
-v, --version Show program version info and exit.
--distpath=DIR Where to put the bundled app (default: .\dist)
--workpath=WORKPATH Where to put all the temporary work files, .log, .pyz
and etc. (default: .\build)
-y, --noconfirm Replace output directory (default:
SPECPATH\dist\SPECNAME) without asking for
confirmation
--upx-dir=UPX_DIR Path to UPX utility (default: search the execution
path)
-a, --ascii Do not include unicode encoding support (default:
included if available)
--clean Clean PyInstaller cache and remove temporary files
before building.
--log-level=LOGLEVEL Amount of detail in build-time console messages
(default: INFO, choose one of DEBUG, INFO, WARN,
ERROR, CRITICAL) What to generate:
-F, --onefile Create a one-file bundled executable.
-D, --onedir Create a one-folder bundle containing an executable
(default)
--specpath=DIR Folder to store the generated spec file (default:
current directory)
-n NAME, --name=NAME
Name to assign to the bundled app and spec file
(default: first script's basename) What to bundle, where to search:
-p DIR, --paths=DIR
A path to search for imports (like using PYTHONPATH).
Multiple paths are allowed, separated by ';', or use
this option multiple times
--hidden-import=MODULENAME
Name an import not visible in the code of the
script(s). This option can be used multiple times.
--additional-hooks-dir=HOOKSPATH
An additional path to search for hooks. This option
can be used multiple times.
--runtime-hook=RUNTIME_HOOKS
Path to a custom runtime hook file. A runtime hook is
code that is bundled with the executable and is
executed before any other code or module to set up
special features of the runtime environment. This
option can be used multiple times.
--exclude-module=EXCLUDES
Optional module or package (his Python names,not path
names) that will be ignored (as thoughit was not
found).This option can be used multiple times.
--key=KEY The key used to encrypt Python bytecode. How to generate:
-d, --debug Tell the bootloader to issue progress messages while
initializing and starting the bundled app. Used to
diagnose problems with missing imports.
-s, --strip Apply a symbol-table strip to the executable and
shared libs (not recommended for Windows)
--noupx Do not use UPX even if it is available (works
differently between Windows and *nix) Windows and Mac OS X specific options:
-c, --console, --nowindowed
Open a console window for standard i/o (default)
-w, --windowed, --noconsole
Windows and Mac OS X: do not provide a console window
for standard i/o. On Mac OS X this also triggers
building an OS X .app bundle.This option is ignored in
*NIX systems.
-i <FILE.ico or FILE.exe,ID or FILE.icns>, --icon=<FILE.ico or FILE.exe,ID or FILE.icns>
FILE.ico: apply that icon to a Windows executable.
FILE.exe,ID, extract the icon with ID from an exe.
FILE.icns: apply the icon to the .app bundle on Mac OS
X Windows specific options:
--version-file=FILE
add a version resource from FILE to the exe
-m <FILE or XML>, --manifest=<FILE or XML>
add manifest FILE or XML to the exe
-r <FILE[,TYPE[,NAME[,LANGUAGE]]]>, --resource=<FILE[,TYPE[,NAME[,LANGUAGE]]]>
Add or update a resource of the given type, name and
language from FILE to a Windows executable. FILE can
be a data file or an exe/dll. For data files, at least
TYPE and NAME must be specified. LANGUAGE defaults to
0 or may be specified as wildcard * to update all
resources of the given TYPE and NAME. For exe/dll
files, all resources from FILE will be added/updated
to the final executable if TYPE, NAME and LANGUAGE are
omitted or specified as wildcard *.This option can be
used multiple times.
--uac-admin Using this option creates a Manifest which will
request elevation upon application restart.
--uac-uiaccess Using this option allows an elevated application to
work with Remote Desktop. Windows Side-by-side Assembly searching options (advanced):
--win-private-assemblies
Any Shared Assemblies bundled into the application
will be changed into Private Assemblies. This means
the exact versions of these assemblies will always be
used, and any newer versions installed on user
machines at the system level will be ignored.
--win-no-prefer-redirects
While searching for Shared or Private Assemblies to
bundle into the application, PyInstaller will prefer
not to follow policies that redirect to newer
versions, and will try to bundle the exact versions of
the assembly. Mac OS X specific options:
--osx-bundle-identifier=BUNDLE_IDENTIFIER
Mac OS X .app bundle identifier is used as the default
unique program name for code signing purposes. The
usual form is a hierarchical name in reverse DNS
notation. For example:
com.mycompany.department.appname (default: first
script's basename) Obsolete options (not used anymore):
-X, -K, -C, -o, --upx, --tk, --configfile, --skip-configure, --out, --buildpath
These options do not exist anymore.

  

2.2 常用参数说明

  • -D 创建一个目录,里面包含exe以及其他一些依赖性文件
  • -F 表示生成单个可执行文件
  • -w 表示去掉控制台窗口,在GUI界面时非常有用
  • -i 表示可执行文件的图标,请使用*.ico格式图片

需要特别强调的是-i参数,可执行文件图标要求如下:

Windows XP:

Explorer views:
Details / List: 16
Icons: 32
Tiles / Thumbnails: 48
Right-click->Properties / choosing a new icon: 32
Quickstart area: 16
Desktop: 32
Windows 7: Explorer views:
Details / List / Small symbols: 16
All other options: 256 (resized, if necessary)
Right-click->Properties / choosing a new icon: 32
Pinned to taskbar: 32
Right-click-menu: 16
Desktop:
Small symbols: 32
Medium symbols: 48
Large symbols: 256 (resized, if necessary)
Zooming using Ctrl+Mouse wheel: 16, 32, 48, 256

Windows XP uses 16, 32, 48-size icons

while Windows 7 (and presumably also Vista) also uses 256-size icons. 所有中间尺寸会被过滤 

2.3 参数组合使用

2.3.1 smartbit_tool.py打包为一个文件夹、关闭控制台、添加程序图标

pyinstaller -D smartbit_tool.py -w -i .\ico\magnifier.ico

2.3.2 smartbit_tool.py打包为单个文件、关闭控制台、添加程序图标

pyinstaller -F smartbit_tool.py -w -i .\ico\magnifier.ico

  

2.4 程序图标下载网站

https://www.easyicon.net/

提供各种尺寸图片下载,非常方便!

pyqt pyinstaller使用说明的更多相关文章

  1. pyinstaller打包pyqt文件

    打包pyqt文件 如何将pyqt生成exe的二进制文件呢,pyinstaller就是这样的工具 可以将脚本文件.py 文件转换为编辑后的二进制文件,在进行发布 下面说下,如果打包 一. 安装: 下载地 ...

  2. pyinstaller打包pyqt文件(转)

    pyinstaller打包pyqt文件  https://www.cnblogs.com/dcb3688/p/4211390.html   打包pyqt文件 如何将pyqt生成exe的二进制文件呢,p ...

  3. python脚本 pyqt 打包成windows可执行exe文件 pyinstaller

    今天学习pyqt,做了一些好玩的东西. 好奇之中想试试python脚本编译成可执行文件,一顿查询之后成功了! 我的环境是: windows10 64bit    python3.5    pyqt5 ...

  4. PyQt(Python+Qt)学习随笔:windows下使用pyinstaller将PyQt文件打包成exe可执行文件

    专栏:Python基础教程目录 专栏:使用PyQt开发图形界面Python应用 专栏:PyQt入门学习 老猿Python博文目录 在<windows下使用pyinstaller将多个目录的Pyt ...

  5. 用pyinstaller打包python程序、打包pyqt程序

    将.py脚本拷贝到一个文件夹中: 然后shift+右键,打开Powershell窗口: -F:设置打包为一个.exe文件.(缺点打开速度慢,不加-F则不打包为一个.exe,优点简洁方便) -w:设置不 ...

  6. Pyqt 获取打包二进制文件中的资源

    记得有一次打开一个单独exe程序,点击btn中的一个帮助说明按钮,在同级目录下就多出一个help.chm 文件并自动打开. 那这个exe肯定是把help.chm 打包到exe中,当我触发“帮助”按钮的 ...

  7. pyinstaller 官方介绍

    http://www.pyinstaller.org/ pyinstaller支持多个平台,windows,linux,mac,兼容多个第三方包,包括pyqt,django,matplotlib Py ...

  8. Pyqt QSystemTrayIcon 实现托盘效果

    pyqt的托盘效果很好实现,在Pyqt的demo中有个例子 路径:PyQt4\examples\desktop\systray.py 今天我就仿这个Tray效果做效果 一. 创建UI trayicon ...

  9. 解决Pyqt打包后运行报错:应用程序无法启动 因为程序的并行配置不正确

    做了一个生成二维码的小程序:http://www.cnblogs.com/dcb3688/p/4241048.html 直接运行脚本没问题,用pyinstaller打包后再运行就直接报错了: 应用程序 ...

随机推荐

  1. 用Python完成毫秒级抢单,助你秒杀淘宝大单

    目录: 引言 环境 需求分析&前期准备 淘宝购物流程回顾 秒杀的实现 代码梳理 总结 0 引言 年中购物618大狂欢开始了,各大电商又开始了大力度的折扣促销,我们的小胖又给大家谋了一波福利,淘 ...

  2. internet信息服务(IIS)管理器 在哪里?

    我们在搭建网络配置时就需要找到internet信息服务(IIS)管理器,下面我们就来看看internet信息服务(IIS)管理器在哪里能够找到. 工具/材料 使用工具:电脑 01 02 03 04 0 ...

  3. FCC-学习笔记 Sorted Union

    FCC-学习笔记  Sorted Union 1>最近在学习和练习FCC的题目.这个真的比较的好,推荐给大家. 2>中文版的地址:https://www.freecodecamp.cn/; ...

  4. python3匿名函数

    当我们在传入函数时,有些时候,不需要显式地定义函数,直接传入匿名函数更方便. 在Python中,对匿名函数提供了有限支持.还是以map()函数为例,计算f(x)=x2时,除了定义一个f(x)的函数外, ...

  5. Xml格式数据转map工具类

    前言[ 最近在写一个业务,由于调UPS物流的接口返回的是一个xml格式的数据结果,我现在要拿到xml中某个节点的值,而这个xml数据是多节点多层级的,并且这某个节点的值有可能只有一条值,有可能有多条, ...

  6. day08 作业

    1. 有如下值集合 [11,22,33,44,55,66,77,88,99,90...],将所有大于 66 的值保存至字典的第一个key中,将小于 66 的值保存至第二个key的值中 即: {'k1' ...

  7. commons-dbutils【不推荐】

    Apache 组织提供的一个开源 JDBC工具类库,它是对JDBC的简单封装. 一般项目开发过程中,要么选择 ORM框架,要么自己编写DBUtils类+数据库连接池就足够了.

  8. requests---session简介

    http协议是无状态的,也就是每个请求都是独立的.那么登录后的一系列动作,都需要用cookie来验证身份是否是登录状态,为了高效的管理会话,保持会话,于是就有了session session简介 se ...

  9. django中嵌套的try-except

    # 因为此时为yaml模板,而且只抓取node port,所以这样处理效率快content_dict = parse_yaml(content.replace("{{", &quo ...

  10. Ansible 相关介绍

    相关视频http://v.xue.taobao.com/learn.htm?spm=a220o.1000855.0.0.24c748e6QMQV0e&courseId=111848 Ansib ...