iis服务器助手广告广告
返回顶部
首页 > 资讯 > 后端开发 > Python >使用PyInstaller把Python
  • 890
分享到

使用PyInstaller把Python

PyInstallerPython 2023-01-31 05:01:48 890人浏览 薄情痞子

Python 官方文档:入门教程 => 点击学习

摘要

1、下载地址:Http://www.pyinstaller.org/ 。2、解压即用(V2.1)。注意环境变量,或者用pyinstaller.py的全路径,或者到解压目录下使用。*^_^*3、打包命令示例:python pyinstalle

1、下载地址:Http://www.pyinstaller.org/ 。

2、解压即用(V2.1)。注意环境变量,或者用pyinstaller.py的全路径,或者到解压目录下使用。*^_^*

3、打包命令示例:

python pyinstaller.py --onefile yourprogram.py

4、参数信息参见手册的Options 。


*** Updated 2015-12-11 ***

1、用pip安装pyinstaller3。

pip3 install pyinstaller

2、打包命令示例:

pyinstaller --onefile yourprogram.py

另外两个常用的参数:

(1)、添加图标

-i walker.ico    //添加图标

(2)、压缩可执行文件(upx)

--upx-dir UPX_DIR    //指定压缩程序(upx.exe)目录,默认当前目录


FAQ:

Q1、ImportError: DLL load failed

A1、walker遇到的情况是引用了pyd文件,而这个pyd文件依赖其他dll库,walker的解决方案是安装VC2010运行时库。


Q2、程序中用到多进程在打包时应注意些什么?

A2、在main函数中添加multiprocessing.freeze_support()语句,参考这里。


Q3、报如下几种错误:

ImportError: No module named _mssql
ImportError: No module named decimal
ImportError: No module named uuid

A3、很可能是代码中用到了pymssql模块,这时的解决步骤是:①、import decimal;②、import uuid;③、重新编译;④、拷贝_mssql.pyd到发布目录。


Q4、打包成功,运行时报如下错误:

Traceback (most recent call last):
  File "main.py", line 9, in <module>
ModuleNotFoundError: No module named 'sub.py'
[4100] Failed to execute script main

A4、walker 排查出的原因是 py 文件编码不一致,main.py 是 utf8 编码,sub.py 是 gbk 编码,统一成 utf8 编码后问题解决。


Q5、Python 3.6,pyinstaller 3.3.1,pywinauto 0.6.4 打包问题可以参考:PyInstaller 3.3.1 does not work with Pywinauto lib import

A5、copy 如下:

Create folder comtypes/gen/ in the same folder of your test.py, 
and copy file _944DE083_8FB8_45CF_BCB7_C477ACB2F897_0_1_0.py and UIAutomationClient.py (under Lib/site-packages/comtypes/gen/) into this folder.
Then use pyinstaller --hidden-import comtypes.gen._944DE083_8FB8_45CF_BCB7_C477ACB2F897_0_1_0 --hidden-import comtypes.gen.UIAutomationClient test.py


相关阅读:

1、Python 打包可执行文件

2、linux下安装pyinstaller用于将py文件打包生成一个可执行文件

3、pyinstaller无法在命令行运行,提示failed to create process.


*** walker * Updated 2018-04-21 ***


--结束END--

本文标题: 使用PyInstaller把Python

本文链接: https://www.lsjlt.com/news/188146.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作