Python項(xiàng)目打包成exe文件
前言
之前有人私信我,他寫(xiě)了一個(gè)在終端交互的小程序,希望可以不在IDE的終端顯示,而是獨(dú)立一個(gè)窗口進(jìn)行交互。其實(shí)只要把項(xiàng)目打包成exe執(zhí)行文件,就可以在執(zhí)行的時(shí)候在cmd獨(dú)立一個(gè)窗口了。
如果python項(xiàng)目打包exe呢?下面按照步驟講解一下。
環(huán)境依賴
安裝pyinstaller。
pip install pyinstaller -i https://pypi.douban.com/simple
項(xiàng)目打包
項(xiàng)目部分代碼
先看一下項(xiàng)目在終端執(zhí)行的效果。
使用pyinstaller命令在打包將main方法打包。
pyinstaller -F main.py
打包過(guò)程
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>
會(huì)在dist生成exe文件,就是我們要的。
雙擊執(zhí)行一下
?
總結(jié)
沒(méi)啥總結(jié)的,做個(gè)記錄。
到此這篇關(guān)于Python項(xiàng)目打包成exe文件的文章就介紹到這了,更多相關(guān)Python打包成exe文件內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Python zip()函數(shù)用法實(shí)例分析
這篇文章主要介紹了Python zip()函數(shù)用法,結(jié)合實(shí)例形式較為詳細(xì)的分析了Python zip()函數(shù)的功能、使用方法及相關(guān)操作注意事項(xiàng),需要的朋友可以參考下2018-03-03tensorflow學(xué)習(xí)教程之文本分類詳析
初學(xué)tensorflow,借鑒了很多別人的經(jīng)驗(yàn),參考博客對(duì)評(píng)論分類(感謝博主的一系列好文),本人也嘗試著實(shí)現(xiàn)了對(duì)文本數(shù)據(jù)的分類,下面這篇文章主要給大家介紹了關(guān)于tensorflow學(xué)習(xí)教程之文本分類的相關(guān)資料,需要的朋友可以參考下2018-08-08對(duì)numpy.append()里的axis的用法詳解
今天小編就為大家分享一篇對(duì)numpy.append()里的axis的用法詳解,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-06-06Python正則表達(dá)式和re庫(kù)知識(shí)點(diǎn)總結(jié)
在本篇文章中小編給大家分享了關(guān)于Python正則表達(dá)式和re庫(kù)知識(shí)點(diǎn)內(nèi)容,有興趣的朋友們學(xué)習(xí)下。2019-02-02python turtle庫(kù)畫(huà)一個(gè)方格和圓實(shí)例
在本篇文章里小編給大家分享了關(guān)于python中用turtle庫(kù)畫(huà)一個(gè)方格和圓實(shí)例和相關(guān)代碼,需要的朋友們可以學(xué)習(xí)參考下。2019-06-06