轉:Python用PyInstaller打包筆記

來源:互聯網
上載者:User

標籤:

轉自http://www.itoldme.net/archives/1242

為了把python發行到沒有安裝python的Windows環境使用,需要打包成exe可執行檔。現在常見的python打包工具有cx_Freeze、PyInstaller和py2exe,想想我當初接觸python的時候,似乎只有py2exe,而且有不少問題時光荏苒,一切過的真快。本文介紹PyInstaller打包的使用。

一.準備工作安裝PyWin32

到http://sourceforge.net/projects/pywin32/下載 PyWin32,本文使用的是 pywin32-219.win-amd64-py2.7,地址:http://sourceforge.net/projects/pywin32/files/pywin32/Build%20219/pywin32-219.win-amd64-py2.7.exe/download

下載PyInstaller

到http://www.pyinstaller.org/下載PyInstaller並解壓縮。本文使用PyInstaller 2.1。

或者使用pip安裝,執行pip install pyinstaller

下載upx(可選)

到http://upx.sourceforge.net/下載upx,解壓後把upx放在PyInstaller目錄下,upx的作用是給產生的exe加殼,減小體積。

二.使用方法

cmd切換到PyInstaller檔案夾,執行命令,如:

pyinstaller myscript.py

當然也可以添加輸出選項,獲得更好的exe可執行檔,如:

python pyinstaller.py --upx-dir -F xxx.py

-F用於製作獨立的可執行程式,--upx-dir用於壓縮檔。

注意:

  • 網上教程常見的-X選項啟用upx已經失效
  • 如果upx.exe已經複製到PyInstaller檔案夾下,會預設使用upx,如果不在檔案夾下,可以使用--upx-dir選項,如--upx-dir=upx_dir,如--upx-dir=/usr/local/share/
  • 如果upx.exe複製到了PyInstaller檔案夾下,如果不想使用upx,需要添加參數 --noupx
三.常用參數介紹

-F 用於製作獨立的可執行程式

--upx-dir 使用upx加殼從而壓縮exe檔案

--noconsole適用於Windows和Mac OS X,用於建立不顯示控制台視窗的程式

其他

PyInstaller可以用於多個平台的打包,包括 Windows (32-bit and 64-bit),Linux (32-bit and 64-bit),Mac OS X (32-bit and 64-bit),experimentally Solaris and AIX。

PyInstaller也可以自訂ico檔案等,完整使用手冊參見http://pythonhosted.org/PyInstaller/

轉:Python用PyInstaller打包筆記

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.