close

透過pip安裝pyinstaller (目前可支援python2.7 and 3.3-3.6)

pip install pyinstaller

 

安裝後打包指令

pyinstaller -F .\test.py    (windows使用者執行指令)

pyinstaller -F ./test.py    (mac使用者執行指令)

執行後陸續新增幾個檔案, 如下所示

1. 建立一個test.spec

2.建立build資料夾, 在資料夾內建立log記錄檔與工作檔案

3. 建立dist資料夾, 在資料夾內建立執行檔(.exe)

 

如果執行後發生錯誤如下:

Traceback (most recent call last):
  File "<string>", line 2, in <module>
ModuleNotFoundError: No module named 'setuptools._vendor'

請下指令安裝setuptools

python -m pip install -U pip setuptools

 

常用參數介紹

1. pyinstaller -h 查看參數

2. -F 打包成一個exe文件

3. -icon=圖標路徑  (pyinstaller -F -i test.ico  test.py)  

※圖片格式.ico

※圖片大小64x64, 128x128, ...

※只能替換掉exe檔的圖片, 啟動程式左上角的圖片依舊會是一根羽毛

4. -w 使用視窗, 無控制台

5. -c 使用控制台, 無視窗

6. -D 創建一個目錄, 包含exe以及其他一些依賴性文件

arrow
arrow

    楓綺 發表在 痞客邦 留言(0) 人氣()