標籤:需要 aci utf8 pytho 匯入模組 down 表徵圖 支援 tar
需求分析:
python指令碼如果在沒有安裝python的機器上不能運行,所以將指令碼打包成exe檔案,降低指令碼對環境的依賴性,同時運行更加迅速。
當然打包的指令碼似乎不是在所有的win平台下都能使用,win7有一部分不能使用,我在win10能夠很好的運行。
準備:
pyinstaller(http://www.pyinstaller.org/) 首先還是去官網看支援的python版本,不然會很尷尬的
安裝方法1:
安裝pyinstaller和pywin32
使用一下命令將自動安裝兩個包,在cmd用pip命令
pip install https://github.com/pyinstaller/pyinstaller/archive/develop.tar.gz
安裝方法二:
pip install pyinstaller (會自動下載future,pywin32,pyinstaller)
如何使用Pyinstaller
方法一:
1.cmd到/python/scripts 找到pyinstaller.exe
2.輸入命令
| 1 |
pyinstaller.exe -F path:demo.py |
方法二:
1.進入pyinstaller的解壓包,輸入命令
2."python pyinstaller.py -F path:demo.py"
從cmd最後一行輸出可尋找到產生的檔案
12468 INFO: Appending archive to EXE D:\Documents\Downloads\PyInstaller-3.2\download\dist\download.exe
後記:
1.程式設定自訂表徵圖:pyinstaller -F -i ico_path py_path
首先需要下載一張正常的ico,不能用直接修改尾碼的。
下載圖片: https://www.easyicon.net
圖片改為ico: http://www.ico.la/
輸入命令 pyinstaller -F -i "demo.ico" "main.py"
2.報錯提示:
pyinstaller -F -i "demo.ico" "main.py" 命令格式一定是先表徵圖路徑,再程式路徑。
路徑最好為英文,沒有中文字元;指令碼名稱裡沒有特殊字元如 .
使用utf8編碼
表徵圖檔案必須是正常格式,不能直接更改尾碼。
tuble index out of range ---》pyinstaller版本尚未支援python的版本
3.視窗程序
使用 pyinstaller -F -w -i ico_path py_path ,這樣指令碼不會彈出命令窗,前提是用了GUI庫.
4.匯入模組問題
pyinstaller -F -w -i --hidden-import queue ico_path py_path 加上選項
python pyinstaller安裝