Py2exe,Python转换为exe可执行文件,脱离Python运行环境运行

官方网站 http://www.py2exe.org/ 很奇怪的站点 一半中文一半英文,不知道是不是作者是中国人。

我使用的是Python2.6,于是下载了一个Python2.6的文件安装测试了一下 http://sourceforge.net/projects/py2exe/files/py2exe/0.6.9/py2exe-0.6.9.win32-py2.6.exe/download

话说这个东西已经2,3年没更新了.

[python]#!/usr/bin/env python
# -*- coding=utf-8 -*-
#Using GPL v2
#Author: ihipop@gmail.com

# hello.py
import os
def main():
print "Hello, World!"
print u'你好,Python!'

if __name__ == '__main__':
main()
raw_input(u'Python真好用!'.encode('gbk'))
[/python]

再同一级别目录下面新建一个setup.py

[python]#!/usr/bin/env python
# -*- coding=utf-8 -*-
#Using GPL v2
#Author: ihipop@gmail.com

from distutils.core import setup
import py2exe

#setup(console=["hello.py"])
#console 命令行程序Only windows GUI程序

includes = ["encodings", "encodings.*"]
#要包含的其它库文件

options = {"py2exe":
{ "compressed": 1,#压缩
"optimize": 2,
"includes": includes,#上面定义的includes变量
"bundle_files": 1,##所有文件打包成一个exe文件,不能从文件系统中加载python模块;2表示pyd和dll文件会被打包到exe文件中#但是可以从文件系统中加载python模块。(新版功能)
}
}

setup(
version = "0.1.0",
description = "This is A Test!",
name = "Hoto",
options = options,#上面定义的options变量
#不生产zip的库文件
zipfile=None,
console=[{"script": "hello.py", "icon_resources": [(1, "favicon.ico")]}]#script指定Python脚本文件,icon_resources是图标文件
)
[/python]

开始编译

[text]setup.py py2exe[/text]

[text]
running py2exe
*** searching for required modules ***
*** parsing results ***
creating python loader for extension 'select' (E:\Python26\DLLs\select.pyd -> select.pyd)
creating python loader for extension 'unicodedata' (E:\Python26\DLLs\unicodedata.pyd -> unicodedata.pyd)
creating python loader for extension 'bz2' (E:\Python26\DLLs\bz2.pyd -> bz2.pyd)
*** finding dlls needed ***
*** create binaries ***
*** byte compile python files ***
byte-compiling C:\Downloads\build\bdist.win32\winexe\temp\bz2.py to bz2.pyc
byte-compiling C:\Downloads\build\bdist.win32\winexe\temp\select.py to select.pyc
byte-compiling C:\Downloads\build\bdist.win32\winexe\temp\unicodedata.py to unicodedata.pyc
skipping byte-compilation of E:\Python26\lib\StringIO.py to StringIO.pyc
#略过
skipping byte-compilation of E:\Python26\lib\warnings.py to warnings.pyc
*** copy extensions ***
*** copy dlls ***
copying E:\Python26\lib\site-packages\py2exe\run.exe -> C:\Downloads\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.

WSOCK32.dll - C:\WINDOWS\system32\WSOCK32.dll
USER32.dll - C:\WINDOWS\system32\USER32.dll
ADVAPI32.dll - C:\WINDOWS\system32\ADVAPI32.dll
SHELL32.dll - C:\WINDOWS\system32\SHELL32.dll
KERNEL32.dll - C:\WINDOWS\system32\KERNEL32.dll
[/text]

编译生成的文件在dist里面,里面有现成的二进制运行库,我看了一下,体积不小哦。

官方Tutorial: http://www.py2exe.org/index.cgi/Tutorial

参考:http://blog.csdn.net/suiyunonghen/archive/2009/03/29/4033076.aspx

Author Info :
  • From:Py2exe,Python转换为exe可执行文件,脱离Python运行环境运行
  • URL:https://blog.ihipop.info/2011/02/2102.html
  • Please Reserve This Link,Thanks!
  • 《Py2exe,Python转换为exe可执行文件,脱离Python运行环境运行》上有6条评论

    1. 和中国人一点关系没有,仅仅是这个站的建站系统(The MoinMoin Wiki Engine)对国际化支持比较好而已。

    发表评论

    您的电子邮箱地址不会被公开。 必填项已用*标注