Python pyinstaller

Python pyinstaller

Python 默認並不包含 PyInstaller 模塊,因此需要自行安裝 PyInstaller 模塊。

 一、安裝 Pyinstaller

安裝 Pyinstaller
        官網  http://www.pyinstaller.org/
        使用pip命令安裝:pip install pyinstaller

 

安裝之後,會有 pyinstaller.exe

 

 

D:\Program Files\python_3_6_4\Scripts>pip show pyinstaller
Name: pyinstaller
Version: 4.8
Summary: PyInstaller bundles a Python application and all its dependencies into a single package.
Home-page: http://www.pyinstaller.org/
Author: Hartmut Goebel, Giovanni Bajo, David Vierra, David Cortesi, Martin Zibricky
Author-email:
License: GPLv2-or-later with a special exception which allows to use PyInstaller to build and distribute non-free programs (including commercial ones)
Location: d:\program files\python_3_6_4\lib\site-packages
Requires: altgraph, importlib-metadata, pefile, pyinstaller-hooks-contrib, pywin32-ctypes, setuptools
Required-by:

 

把 pyinstaller.exe 的路徑加到系統的環境變量的 path 裏面,以後在 cmd 窗口可以使用。

 

 

 
二、使用Pyinstaller

1、 打開 cmd 窗口,把路徑切換到文件所在路徑(文件隨便放在哪裏都行)打開命令提示行,輸入以下內容(最後的是文件名):

        cd  D:\temp-test\RecordScreen
        pyinstaller -F division_test.py

 

會生成兩個文件夾 build 和 dist , 生成的 exe 在 dist 中。

 

 

 

 

 


2、輸入參數的含義

    -F 表示生成單個可執行文件( -D 多個文件)。
    -w 表示去掉控制檯窗口,這在GUI界面時非常有用。不過如果是命令行程序的話那就把這個選項刪除吧。
    -p 表示你自己自定義需要加載的類路徑,一般情況下用不到。
    -i 表示可執行文件的圖標。

三、注意事項

文件中使用了第三方庫的打包方式

 

 

 

 


在打包之前務必找到第三方庫的包,把包複製到跟 division_test.py  同目錄下,然後再打包,否則會打包失敗或者即使打包成功,程序也會閃退。

 
給程序換圖標的方法
            輸入命令中添加一個 -i tubiao.ico (圖標的相對路徑)。

四、exe文件生成

    如果程序打包過程沒有報錯,則會生成3個文件夾(有時候是2個),其中名爲 dist 的文件夾中會有一個 division_test.exe 文件,運行一下,如果沒有問題就打包成功,可以把這個exe文件單獨拿出去用,其他的生成的文件夾可以刪掉了。

    

REF
http://www.cnblogs.com/gopythoner/p/6337543.html

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章