将Python代码打包成.exe可执行程序
发布日期:2021-09-14 23:17:56
浏览次数:6
分类:技术文章
本文共 3141 字,大约阅读时间需要 10 分钟。
其实很简单,首先安装pyinstaller包:
# 打开cmdpip install pyinstaller
安装后,通过cmd
pyinstaller -F D:\xxx\xx.py
还有别的参数,具体移步,这边仅简单演示一下
打包成功,会显示.exe文件的位置,找到便可直接运行
附打包成功的截图:D:\xxx>pyinstaller -F xx.py43 INFO: PyInstaller: 4.043 INFO: Python: 3.7.743 INFO: Platform: Windows-10-10.0.18362-SP044 INFO: wrote D:\xxx\xx.spec48 INFO: UPX is not available.61 INFO: Extending PYTHONPATH with paths['D:\\xxx', 'D:\\xxx']84 INFO: checking Analysis84 INFO: Building Analysis because Analysis-00.toc is non existent84 INFO: Initializing module dependency graph...88 INFO: Caching module graph hooks...104 INFO: Analyzing base_library.zip ...1632 INFO: Processing pre-find module path hook distutils from 'c:\\program files\\python37\\lib\\site-packages\\PyInstaller\\hooks\\pre_find_module_path\\hook-distutils.py'.1633 INFO: distutils: retargeting to non-venv dir 'c:\\program files\\python37\\lib'2599 INFO: Caching module dependency graph...2798 INFO: running Analysis Analysis-00.toc2800 INFO: Adding Microsoft.Windows.Common-Controls to dependent assemblies of final executable required by c:\program files\python37\python.exe2863 INFO: Analyzing D:\xxx\xx.py2865 INFO: Processing module hooks...2865 INFO: Loading module hook 'hook-distutils.py' from 'c:\\program files\\python37\\lib\\site-packages\\PyInstaller\\hooks'...2866 INFO: Loading module hook 'hook-encodings.py' from 'c:\\program files\\python37\\lib\\site-packages\\PyInstaller\\hooks'...2958 INFO: Loading module hook 'hook-sysconfig.py' from 'c:\\program files\\python37\\lib\\site-packages\\PyInstaller\\hooks'...2959 INFO: Loading module hook 'hook-xml.py' from 'c:\\program files\\python37\\lib\\site-packages\\PyInstaller\\hooks'...3149 INFO: Looking for ctypes DLLs3149 INFO: Analyzing run-time hooks ...3155 INFO: Looking for dynamic libraries3290 INFO: Looking for eggs3291 INFO: Using Python library c:\program files\python37\python37.dll3291 INFO: Found binding redirects:[]3293 INFO: Warnings written to D:\xxx\build\xx\warn-xx.txt3320 INFO: Graph cross-reference written to D:\xxx\build\xx\xref-xx.html3337 INFO: checking PYZ3337 INFO: Building PYZ because PYZ-00.toc is non existent3338 INFO: Building PYZ (ZlibArchive) D:\xxx\build\xx\PYZ-00.pyz3734 INFO: Building PYZ (ZlibArchive) D:\xxx\build\xx\PYZ-00.pyz completed successfully.3739 INFO: checking PKG3739 INFO: Building PKG because PKG-00.toc is non existent3740 INFO: Building PKG (CArchive) PKG-00.pkg5014 INFO: Building PKG (CArchive) PKG-00.pkg completed successfully.5015 INFO: Bootloader c:\program files\python37\lib\site-packages\PyInstaller\bootloader\Windows-64bit\run.exe5015 INFO: checking EXE5016 INFO: Building EXE because EXE-00.toc is non existent5016 INFO: Building EXE from EXE-00.toc5017 INFO: Appending archive to EXE D:\xxx\dist\xx.exe5021 INFO: Building EXE from EXE-00.toc completed successfully.
其中,-F 表示打包成单独的 .exe 文件,这时生成的 .exe 文件会比较大,而且运行速度回较慢。仅仅一个 helloworld 程序,生成的文件就 5MB 大。
另外,使用 -i 还可以指定可执行文件的图标;
-w 表示去掉控制台窗口,这在 GUI 界面时非常有用。不过如果是命令行程序的话那就把这个选项删除吧!PyInstaller 会对脚本进行解析,并做出如下动作:
1、在脚本目录生成 helloworld.spec 文件;
2、创建一个 build 目录; 3、写入一些日志文件和中间流程文件到 build 目录; 4、创建 dist 目录; 5、生成可执行文件到 dist 目录;后又看到了另一种方法:
转载地址:https://blog.csdn.net/weixin_43451928/article/details/108626672 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
哈哈,博客排版真的漂亮呢~
[***.90.31.176]2024年03月22日 17时04分10秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
简单的留言板网页
2019-04-26
如何快速的搭建Apache+MySQL+PHP+PERL的环境
2019-04-26
初识JavaScript
2019-04-26
JavaScript的常用互动方法
2019-04-26
JavaScript的DOM操作
2019-04-26
JavaScript的事件响应与网页交互
2019-04-26
JavaScript实现的网页计算器功能
2019-04-26
英语四六级考试忘记准考证?怎么办?
2019-04-26
JavaScript内置对象
2019-04-26
JavaScript的游览器对象
2019-04-26
DOM对象,控制HTML对象
2019-04-26
制作一个表格,显示班级的学生信息
2019-04-26
JavaScript的选项卡操作
2019-04-26
Linux常用命令及文件处理命令
2019-04-26
Linux常见目录及作用
2019-04-26
文件链接命令
2019-04-26
Oracle篇--05 Oracle 视图、序列、约束
2019-04-26
【Java面试题四】sql面试题(1)
2019-04-26
【Java面试题五】sql面试题(2)
2019-04-26
【Java面试题六】多线程篇
2019-04-26