Python项目打包成exe文件
程序员文章站
2022-03-05 17:44:42
目录前言环境依赖项目打包总结前言之前有人私信我,他写了一个在终端交互的小程序,希望可以不在ide的终端显示,而是独立一个窗口进行交互。其实只要把项目打包成exe执行文件,就可以在执行的时候在cmd独立...
前言
之前有人私信我,他写了一个在终端交互的小程序,希望可以不在ide的终端显示,而是独立一个窗口进行交互。其实只要把项目打包成exe执行文件,就可以在执行的时候在cmd独立一个窗口了。
如果python项目打包exe呢?下面按照步骤讲解一下。
环境依赖
安装pyinstaller。
pip install pyinstaller -i https://pypi.douban.com/simple
项目打包
项目部分代码
先看一下项目在终端执行的效果。
使用pyinstaller命令在打包将main方法打包。
pyinstaller -f main.py
打包过程
c:\users\yi\pycharmprojects\txl>pyinstaller -f main.py 143 info: pyinstaller: 4.7 143 info: python: 3.7.6 144 info: platform: windows-10-10.0.19041-sp0 145 info: wrote c:\users\yi\pycharmprojects\txl\main.spec 162 info: upx is not available. 165 info: extending pythonpath with paths ['c:\\users\\yi\\pycharmprojects\\txl'] 640 info: checking analysis 641 info: building analysis because analysis-00.toc is non existent 641 info: initializing module dependency graph... 649 info: caching module graph hooks... 696 info: analyzing base_library.zip ... 4371 info: caching module dependency graph... 4614 info: running analysis analysis-00.toc 4619 info: adding microsoft.windows.common-controls to dependent assemblies of final executable required by c:\users\yi\appdata\local\programs\python\python37\python.exe 5046 info: analyzing c:\users\yi\pycharmprojects\txl\main.py 5049 info: processing module hooks... 5050 info: loading module hook 'hook-difflib.py' from 'c:\\users\\yi\\appdata\\local\\programs\\python\\python37\\lib\\site-packages\\pyinstaller\\hooks'... 5052 info: loading module hook 'hook-encodings.py' from 'c:\\users\\yi\\appdata\\local\\programs\\python\\python37\\lib\\site-packages\\pyinstaller\\hooks'... 5253 info: loading module hook 'hook-heapq.py' from 'c:\\users\\yi\\appdata\\local\\programs\\python\\python37\\lib\\site-packages\\pyinstaller\\hooks'... 5256 info: loading module hook 'hook-pickle.py' from 'c:\\users\\yi\\appdata\\local\\programs\\python\\python37\\lib\\site-packages\\pyinstaller\\hooks'... 5260 info: loading module hook 'hook-xml.py' from 'c:\\users\\yi\\appdata\\local\\programs\\python\\python37\\lib\\site-packages\\pyinstaller\\hooks'... 5529 info: looking for ctypes dlls 5529 info: analyzing run-time hooks ... 5532 info: including run-time hook 'c:\\users\\yi\\appdata\\local\\programs\\python\\python37\\lib\\site-packages\\pyinstaller\\hooks\\rthooks\\pyi_rth_pkgutil.py' 5535 info: including run-time hook 'c:\\users\\yi\\appdata\\local\\programs\\python\\python37\\lib\\site-packages\\pyinstaller\\hooks\\rthooks\\pyi_rth_inspect.py' 5542 info: looking for dynamic libraries 5721 info: looking for eggs 5722 info: using python library c:\users\yi\appdata\local\programs\python\python37\python37.dll 5722 info: found binding redirects: [] 5726 info: warnings written to c:\users\yi\pycharmprojects\txl\build\main\warn-main.txt 5765 info: graph cross-reference written to c:\users\yi\pycharmprojects\txl\build\main\xref-main.html 5782 info: checking pyz 5783 info: building pyz because pyz-00.toc is non existent 5783 info: building pyz (zlibarchive) c:\users\yi\pycharmprojects\txl\build\main\pyz-00.pyz 6170 info: building pyz (zlibarchive) c:\users\yi\pycharmprojects\txl\build\main\pyz-00.pyz completed successfully. 6182 info: checking pkg 6182 info: building pkg because pkg-00.toc is non existent 6182 info: building pkg (carchive) main.pkg 7800 info: building pkg (carchive) main.pkg completed successfully. 7803 info: bootloader c:\users\yi\appdata\local\programs\python\python37\lib\site-packages\pyinstaller\bootloader\windows-64bit\run.exe 7803 info: checking exe 7803 info: building exe because exe-00.toc is non existent 7804 info: building exe from exe-00.toc 7805 info: copying bootloader exe to c:\users\yi\pycharmprojects\txl\dist\main.exe 7897 info: copying icon to exe 7897 info: copying icons from ['c:\\users\\yi\\appdata\\local\\programs\\python\\python37\\lib\\site-packages\\pyinstaller\\bootloader\\images\\icon-console.ico'] 7996 info: writing rt_group_icon 0 resource with 104 bytes 7996 info: writing rt_icon 1 resource with 3752 bytes 7997 info: writing rt_icon 2 resource with 2216 bytes 7997 info: writing rt_icon 3 resource with 1384 bytes 7997 info: writing rt_icon 4 resource with 37019 bytes 7997 info: writing rt_icon 5 resource with 9640 bytes 7998 info: writing rt_icon 6 resource with 4264 bytes 7998 info: writing rt_icon 7 resource with 1128 bytes 8002 info: copying 0 resources to exe 8003 info: emedding manifest in exe 8004 info: updating manifest in c:\users\yi\pycharmprojects\txl\dist\main.exe 8007 info: updating resource type 24 name 1 language 0 8011 info: appending pkg archive to exe 9702 info: building exe from exe-00.toc completed successfully. c:\users\yi\pycharmprojects\txl>
会在dist生成exe文件,就是我们要的。
双击执行一下
总结
没啥总结的,做个记录。
到此这篇关于python项目打包成exe文件的文章就介绍到这了,更多相关python打包成exe文件内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!