利用PyInstaller將python程式.py轉為.exe的方法詳解,pyinstaller.py

來源:互聯網
上載者:User

利用PyInstaller將python程式.py轉為.exe的方法詳解,pyinstaller.py

前言

最近經常用到一個.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能帶來一定的協助,如果有疑問大家可以留言交流,謝謝大家對幫客之家的支援。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.