py2exe可以将python腳本轉換成在Windows上的可獨立執行.exe程式的工具。可以讓Python腳本在沒有安裝python工具的Windows系統上運作,友善腳本共享。
操作環境
python2.7.12+Win32
Py2exe安裝方法
1、py2exe子產品下載下傳。下載下傳路徑:py2exe官網,注意py2exe下載下傳版本需要和本地的作業系統位數以及安裝的python版本保持一緻。

2、開始py2exe程式安裝,安裝方法按照提示預設安裝即可。
Py2exe打包操作步驟
1、進入python程式安裝目錄,如C:\Python27
2、在Python安裝路徑(C:\Python27)建立一個setup.py檔案。假設待轉換的pyton腳本名為hello.py,腳本放置在Python安裝路徑下(C:\Python27)。示例如下:
c:\Python27>type setup.py(以下為添加内容)
from distutils.core import setup
import py2exe
options = {"py2exe":{"compressed": 1, "optimize": 2, "bundle_files": 1}}
setup(console=["hello.py"], options=options, zipfile=None)
參數說明:
(1) bundle_files有效值為(3:不打包,預設值,2:打包,但不打包Python解釋器,1:打包,包括Python解釋器)
(2) zipfile的有效值為(不填(預設): 生成一個library.zip檔案,None:把所有東西打包進.exe檔案中)
3、打開cmd視窗,切換到python的安裝目錄(C:\Python27),并執行指令python setup.py py2exe
c:\Python27>python setup.py py2exe
running py2exe
*** searching for required modules ***
............
*** copy dlls ***
copying c:\Python27\lib\site-packages\py2exe\run.exe -> c:\Python27\dist\hello.exe
*** binary dependencies ***
Your executable(s) also depend on these dlls which are not included,
you may or may not need to distribute them.
Make sure you have the license if you distribute any of them, and
make sure you don't distribute files belonging to the operating system.
USER32.dll - C:\Windows\system32\USER32.dll
SHELL32.dll - C:\Windows\system32\SHELL32.dll
ADVAPI32.dll - C:\Windows\system32\ADVAPI32.dll
WS2_32.dll - C:\Windows\system32\WS2_32.dll
GDI32.dll - C:\Windows\system32\GDI32.dll
KERNEL32.dll - C:\Windows\system32\KERNEL32.dll
4、在C:\Python27\dist目錄下檢視生成的可執行檔案hello.exe。hello.exe即為打包後的可直接在windows上運作的程式。
c:\Python27\dist>dir
驅動器 C 中的卷是 系統
卷的序列号是 0000-0A6F
c:\Python27\dist 的目錄
2017/06/11 20:39 <DIR> .
2017/06/11 20:39 <DIR> ..
2017/06/11 20:39 3,960,694 hello.exe
2016/06/27 15:20 111,616 w9xpopen.exe
2 個檔案 4,072,310 位元組
2 個目錄 17,607,745,536 可用位元組
5、打包完成。
轉載于:https://www.cnblogs.com/linyfeng/p/6740627.html