Python打包EXE檔案的方法

2021-10-10 14:30:55 字數 971 閱讀 4727

1.安裝pyinstaller

python打包exe可執行檔案時,需要使用pyinstaller,可以直接使用命令pip install pyinstaller進行安裝,顯示安裝成功後,就可以開始打包可執行檔案了,如果不太確定也可以使用pip list命令檢視是否存在對應的安裝包及版本。

2.打包單.py檔案

python有時候只需要打包單個.py檔案,這種情況就比較簡單,一般不會遇到什麼問題,直接在cmd下切換目錄到.py檔案所在目錄,執行命令:

pyinstaller -f test.py
將會在對應目錄下生成乙個dist資料夾,可執行檔案test.exe就在dist目錄下,如果別人需要用到,即使沒有python環境,依舊可以正常執行。

3.打包多個.py檔案

打包多個.py檔案的核心語句是:

pyinstaller -f main.py -p py_dir
其中main.py代表的是主程式,是主程式入口檔案,-p後面的都是依賴檔案,依賴檔案目錄最好是寫絕對路徑,像下面一樣:

pyinstaller -f test.py -p d

:\a\pythontest\basis\test\classa.py

import sys

("d:\a\pythontest"

)from basis.test.classa import classa

3)如果還有找不到的模組,可以直接對生成的test.spec檔案進行操作,報錯缺少什麼模組,就在紅框中新增對應的模組資訊。

不論是單檔案打包,還是多檔案打包,最後生成的可執行檔案,只需要在cmd下切換到.exe所在目錄,執行對應的操作即可。

python檔案打包成exe

將自己寫的python檔案壓縮成exe有兩種方法 1 使用pyinstaller step1 安裝pyinstaller,在cmd視窗使用pip install pyinstaller安裝 step2 cd 到你的檔案目錄cd d py python testcases slice step3 執行...

python打包成EXE檔案

在我們完成乙個python專案或乙個程式時,由於不可能讓使用者去安裝一些環境,所以希望將python的py檔案打包成在windows系統下直接可以執行的exe程式。在這裡我用的是pyinstaller來打包檔案 首先安裝pyinstaller pip install pyinstaller 輸入 格...

python程式打包EXE檔案

目的 解決pyinstaller打包程式啟動慢的缺點 安裝pyinstaller pip install pyinstaller使用pyinstaller打包 python程式 pyinstaller命令解釋 不能使用 f,打包成獨立exe檔案 pyinstaller w i 圖示.ico 路徑 檔...