前言
最近經常用到一個.py程序,但是每次在不同電腦上用,希望能把Python腳本發布為脫離Python平臺運行的可執行程序,比如單個exe。PyInstalle滿足要求。
PyInstaller本身并不屬于Python包。在安裝 pyinstaller之前需把python環境配置好。
安裝pyinstaller
下載pyinstaller
解壓到F:/PyInstaller-2.1(自選)(可以去官網下載最新版)
安裝pywin32
pywin32-217.win32-py2.7.exe:點擊下載
安裝pyinstaller
1、進入cmd
cd F:/PyInstaller-2.1
python pyinstaller.py --console --onefile test.py
如果提示:
Usage: python pyinstaller.py [opts] [ …] | pyinstaller.py: error: Requires at least one scriptname file or exactly one .spec-file
則說明安裝完成了。
測試打包
1、文件放在當前目錄的pyinstaller-2.1文件夾里面
cd F:/PyInstaller-2.1
python pyinstaller.py --console --onefile test.py
2、命令運行成功后會生成一個test文件夾。在這個文件夾下面會有一個名為dist的文件夾,此文件夾下面有轉換好的test.exe
3、上面編譯出來的exe能夠正常運行了,但帶一個黑色的console,以下重新編譯,加入–windowed –icon,取消–console
python pyinstaller.py -w --onefile --icon="my.ico" test.py
其中my.ico是你要給他加的自定義圖標文件。
總結
以上就是這篇文章的全部內容了,希望本文的內容對大家學習或者使用python能帶來一定的幫助,如果有疑問大家可以留言交流,謝謝大家對武林站長站的支持。
新聞熱點
疑難解答