Python 利用 pyinstaller 打包 PyQt 視窗軟體 exe 執行檔

先前介紹過利用 Py2exe 來打包 PyQt 這次我們使用另一個套件 pyinstaller 來打包 PyQt 網路上的文件介紹到使用該方法較簡單,但實際操作的過程中一波三折,老實講各種文件做法好幾種,結果通通失敗,最終誤打誤撞試成功,本次則詳細記錄操作過程,如下:
首先系統環境介紹
windows7 64 bit
python 2.7 (32 bit)
pywin32-220.win32-py2.7.exe (直接去裝這個版本)
PyInstaller-3.1.1 (我是用這個版本)
下載 pyinstaller 後,其實這個套件也不能說是個套件,使用方法又非常奇怪,建議放在c:/底下,使用 cmd 切換到該目錄,執行命令 python setup.py install 看到安裝成功後,請自行到 C:\Python27\Scripts 檢查是否出現 pyinstaller.exe ,若一切都順利,才可以進行打包工作。

以上環境設定好了,接下來就是回到 pyinstaller 資料夾中,先更改 pyinstaller.py 文件如下

#! /usr/bin/env python
#-----------------------------------------------------------------------------
# Copyright (c) 2013, PyInstaller Development Team.
#
# Distributed under the terms of the GNU General Public License with exception
# for distributing bootloader.
#
# The full license is in the file COPYING.txt, distributed with this software.
#-----------------------------------------------------------------------------


"""
Main command-line interface to PyInstaller.
"""

if __name__ == '__main__':
    from PyInstaller.main import run
    run()




建議舊有的文件另存!!

然後我們依然使用前次的範例程式來執行,利用 cmd 下命令
python pyinstaller.py -F -w PyQtStandarDialog.py

-- 參數說明:

-F, --onefile Py程式碼只有一個文件

-D, --onedir Py程式碼放在一個目錄中(預設是這個)

-K, --tk 包含TCL/TK

-d, --debug 產生debug模式的exe文件

-w, --windowed, --noconsole 窗體exe文件(Windows Only)

-c, --nowindowed, --console 控制台exe文件(Windows Only)

-o DIR, --out=DIR 設置spec文件輸出的目錄,預設在PyInstaller同目錄

--icon=<FILE.ICO> 加入圖標(Windows Only)

-v FILE, --version=FILE 加入版本訊息文件

若順利編譯結束後會產生 PyQtStandarDialog 資料夾,請到 pyinstaller\PyQtStandarDialog\dist 路徑下去找打包的 PyQtStandarDialog.exe 檔案。






留言

這個網誌中的熱門文章

c語言-關於#define用法

CMD常用網管指令

PHP 與 JavaScript 之間傳值利用 json