python程序打包成.exe----pyinstaller工具
1. 环境
windows
2. 安装
运行如下安装命令: pip install pyinstaller==3.0
不要使用3.2版本,编译完成后会报Runtime Error, R6034错误.
3.0版本无此问题。
3. 打包
把.py或.pyw文件拷贝到pyinstaller所在目录
执行命令: pyinstaller -F xxx.py ,会把生成的文件自动放到dist目录下,文件名默认为xxx.exe。
常用参数说明:
-F:把所有文件打包成一个.exe。
-D:把所有文件打包成一个目录,里面包含可执行文件和所需库等其他文件。
-n NAME:重新命名可执行文件。
-w:打开打包后的程序,将不会弹出命令行窗口。
4. 单独文件和目录比较
目录的比单个文件尺寸要大;
目录的比单个文件打开速度要快。
在WIN7上打包,放到XP上,目录的打开失败,单个文件正常。
详细参数说明见文档
http://pythonhosted.org/PyInstaller/#general-options
General 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. |
python程序打包成.exe----pyinstaller工具的更多相关文章
- python + pyinstaller 实现将python程序打包成exe文件直接运行
pyinstaller 我们在平常学习使用python的时候经常会自己编写一些小程序来使用,虽然python是跨平台的语言,但是如果我们想要在一个没有python以及很多库环境的电脑上使用我们的小程序 ...
- Python 程序打包成 exe 可执行文件
Python 程序打包工具 Python 是一个脚本语言,被解释器解释执行.它的发布方式: .py 文件:对于开源项目或者源码没那么重要的,直接提供源码,需要使用者自行安装 Python 并且安装依赖 ...
- 将 Python 程序打包成 .exe 文件
1.简介 做了一个excel的风控模板,里面含有宏,我用python的第三方xlwings部署到linux后发现,linux环境并不支持xlwings. Python 程序都是脚本的方式,一般是在解析 ...
- 将Python 程序打包成 .exe格式入门
PyInstaller PyInstaller 是一个十分有用的第三方库,可以用来打包 python 应用程序,打包完的程序就可以在没有安装 Python 解释器的机器上运行了. 它能够在 Windo ...
- 如何将 Python 程序打包成 .exe 文件?
有不少订阅本公众号的朋友都不是玩 Python,甚至都不是计算机相关专业的,当我给他们一个 Python 程序时,他们是完全不知道该怎么运行的. 于是我想是不是可以将我的程序打包成可执行文件,直接运行 ...
- 使用py2exe将python程序打包成exe程序
近日帮朋友写了个python小程序,从互联网上抓取一些需要的文章到本地.为了运行方便,希望能转换成exe程序在windows下定期执行.从百度上找了些文章,发现py2exe的应用比较多,遂使用之. 1 ...
- python实战===python程序打包成exe
推荐PyInstaller项目www.pyinstaller.org 安装方法: 先跑pip install pywin32再跑pip install pyinstaller即可 可用一句命令打包 ...
- python程序打包成.exe
安装pyinstaller 方法一:使用pip install pyinstaller 方法二:如果是下载github上的包之后手动安装 包下载 亲测可用:Pyinstaller下载地址,GitHub ...
- 【python基础】python程序打包成.exe运行时会弹出黑框
用python调用.bat或者.exe文件时,一般调用 方式如下: os.system("C:\Windows\System32\osk.exe") 对吧,这样就会因为调用了系统s ...
- python程序打包成exe(使用pyinstaller)
pyinstaller下载地址:https://github.com/pyinstaller/pyinstaller/ (这个文件能够自动安装依赖项,其他版本的貌似还要自己安装依赖项) 下载之后解压到 ...
随机推荐
- Storm:最火的流式处理框架
伴随着信息科技日新月异的发展,信息呈现出爆发式的膨胀,人们获取信息的途径也更加多样.更加便捷,同时对于信息的时效性要求也越来越高.举个搜索场景中的例子,当一个卖家发布了一条宝贝信息时,他希望的当然是这 ...
- Jetty与tomcat的比较
Google 应用系统引擎最初是以 Apache Tomcat 作为其 webserver/servlet 容器的,但最终将切换到 Jetty 上. 这个决定让许多开发人员都诧异的想问:为什么要做这样 ...
- Linux里startup.sh 和 shutdown.sh
最近用socket编写了一个服务端程序,监听1024端口,检测客户端发来的请求,所在Linux里写启动和停止的脚本: 在Eclipse里java写好程序,右击导出生成 Runnable JAR fil ...
- 响应性web设计实战总结
响应性web设计实战 响应性web设计的理念是:页面的设计与开发应当根据用户行为与设备环境(包括系统平台,屏幕尺寸,屏幕定向等)进行相应的响应及调整.具体的实践方式由多方面组成,包括弹性网格和布局,图 ...
- U盘操作系统,Kali Linux操作系统安装
为什么要用U盘装操作系统,那好处多了去了.1.随身携带,想用就用.2.平常娱乐还是用Windows比较方便,不用做双系统那么麻烦. 准备: U盘,从天猫上买了个三星闪存盘,32G,USB3.0: 从官 ...
- spring 缓存(spring自带Cache)(入门)
spring的缓存机制,是方法纬度的缓存机制, 这就意味着我们并不用关注 底层是否使用了数据库以及通过什么方式访问的数据库: 因此,此缓存方法既适用于dao层,也适用于service层. spring ...
- 清北暑假模拟day1 艳阳天
/* 注意P有可能不是质数,不要用欧拉函数那一套,正解可以倍增,就是等比数列和的性质,注意n是否为奇数 */ #include <cstdio> #include <algorith ...
- C#3.0 特性
C#3.0特性 隐式类型的本地变量和数组 对象初始值设定项 集合初始值设定项 扩展方法 匿名类型 lambda表达式 查询关键字 自动实现的属性 分布方法定义 lambda表达式与表达式树 https ...
- Android 如何在Eclipse中查看Android API源码 及 support包源码
当我们阅读android API开发文档时候,上面的每个类,以及类的各个方法都是已经写好的方法和控件,可是我们只是在搬来使用,不知道它的原理,它是如何被实现的.android系统是开源的,所以谷歌官方 ...
- 基于SSL协议的双向认证 - SSL协议 [1]
1 概要说明 在互联网通信方式中,目前用的最广泛的是HTTPS配合SSL和数字证书来保证传输和认证安全了. 2 详细介绍 2.1 HTTPS HTTPS全称:Hypertext Transf ...