把Python腳本打包成exe文件 ——py2exe使用小記

一、相關資源

py2exe官方網站:http://www.py2exe.org/

py2exe使用指南及歷史安裝包:http://www.py2exe.org/old/

支持Python2.7的版本:http://prdownloads.sourceforge.net/py2exe/py2exe-0.6.9.win32-py2.7.exe?download


二、進行打包

創建一個用來打包的Python腳本,Setup.py,例子如下:

# -*- coding: utf-8 -*-

from distutils.core import setup
import py2exe

options = {"py2exe":
            {   "compressed": 1,   
                "optimize": 2,    
                "bundle_files": 1   # 所有文件打包成一個exe文件
            }   
          }   
setup(      
    version = "1.0.0",   
    description = "description for your exe",   
    name = "name for your exe",   
    options = options,   
    zipfile = None, # 不生成zip庫文件  
    console = [{"script": "Hello.py", "icon_resources": [(1, "Hello.ico")] }],     
    )   


Valid values for bundle_files are:

3 (default)

don't bundle

2

bundle everything but the Python interpreter

1

bundle everything, including the Python interpreter


三、其它

目前發現py2exe有一個問題,就是如果有使用pysvn這個庫,創建出來的exe文件是無法正常運行的。

看到有人提出了這是py2exe的一個Bug,也被承認了,但最新的版本中仍未修復這個問題。

http://permalink.gmane.org/gmane.comp.python.py2exe/2738


如果有其它關於使用py2exe的問題,請大家在回覆裏一起討論。

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