.py檔案打包成.exe可執行檔案方法
阿新 • • 發佈:2019-02-15
使用pyinstaller把python程式.py轉化為.exe可執行檔案
在安裝pyinstaller
1. 過python的目錄中執行,假設已經安裝好了pip,使用pip.exe install PyInstaller
使用pip安裝的另一個好處是,pip會自動安裝這個第三方包需要的依賴模組(比如,這裡幫我們下載了pypiwin32這個依賴)。這不,又省心不少
安裝完成後會有一個檔案在同一個目錄中 ,需要先跳轉到script 目錄下才行執行pyinstaller.exe檔案
PyInstaller使用
執行命令 -- pyinstaller.exe [-option] yourname.py
1.1 Option 選項包括:-F, -onefile 打包成一個exe檔案
-D, -onedir 建立一個目錄,包含exe檔案,但會依賴很多檔案(預設選項)
-c, -console, -nowindowed 使用控制檯,無介面(預設)
-w, -windowed, -noconsole 使用視窗,無控制檯
2 編譯要轉化的.py檔案,變成.exe檔案,最後編譯成功後
2.1 -F,-onefile 打包成一個exe檔案
Pyinstaller.exe -F –w yourname.py
2.2 Pyinstaller.exe --console --onefile yourfile只生成一個檔案 .exe (有控制檯cmd視窗)
Pyinstaller.exe --console -D yourfile
2. 在目錄中會有一個dist的檔案生成,就是目標檔案