pyinstaller 打包成可執行exe

2022-09-21 15:48:10 字數 747 閱讀 2318

虛擬環境安裝 pyinstaller

pip install pyinstaller

打包exe命令:(具體的命令網上資料很多)

# 打包1個py檔案,並隱藏執行視窗

pyinstaller -f -w main.py

# 打包1個py檔案(-f),並隱藏執行視窗(-w),替換exe的ico圖示(-i img.ico)

pyinstaller -f -w -i img.ico main.py

以上的這種打包方式會將各種依賴庫都以原始檔方式儲存到資料夾中,大部分時候我們還是希望只有乙個exe檔案

將資料夾中所有依賴庫都打包進exe內:

# 合併到乙個exe內(--onefile),替換exe圖示(--icon=img.ico),py原始檔(main.py),隱藏執行(-w)

pyinstaller --onefile --icon=img.ico main.py -w

注意:當把所有依賴庫都打包進乙個exe以後,且以隱藏cmd視窗方式執行時會出現錯誤,導致程式無法正常執行,所以需要用到

subprocess來執行cmd命令。這種方式來執行cmd命令就不會出現程式錯誤。

import subprocess

cmd = '你的cmd命令'

res = subprocess.call(cmd, shell=true, stdin=subprocess.pipe, stdout=subprocess.pipe, stderr=subprocess.pipe)

pyinstaller打包程式

python打包成exe檔案時,用的是pyinstaller 第一步安裝pyinstaller pip install pyinstaller第二步 pyinstaller f w i ico py其中 ico 是logo,py是你要打包的py檔案 我在打包時出現了struct.error unpa...

pyinstaller打包使用

pyinstaller manage.py 如果直接打包報錯,使用如下命令可以直接生成配置檔案 pyi makespec d manage.py生成的配置檔案格式如下 mode python coding utf 8 block cipher none a analysis impala etl.p...

pyinstaller 打包總結

pyinstaller 打包過程總結 安裝 pyinstaller 打包工具 pip3 install pyinstallerpyinstaller 打包命令不熟悉的小夥伴可點選這裡檢視喲 備註 以下涉及到的檔案名字main.py,請替換成自己的檔名 執行打包命令生成單獨的 exe 程式 pyins...