- 浏览: 13630649 次
- 性别:
- 来自: 洛杉矶
文章分类
- 全部博客 (1994)
- Php / Pear / Mysql / Node.js (378)
- Javascript /Jquery / Bootstrap / Web (435)
- Phone / IOS / Objective-C / Swift (137)
- Ubuntu / Mac / Github / Aptana / Nginx / Shell / Linux (335)
- Perl / Koha / Ruby / Markdown (8)
- Java / Jsp (12)
- Python 2 / Wxpython (25)
- Codeigniter / CakePHP (32)
- Div / Css / XML / HTML5 (179)
- WP / Joomla! / Magento / Shopify / Drupal / Moodle / Zimbra (275)
- Apache / VPN / Software (31)
- AS3.0/2.0 / Flex / Flash (45)
- Smarty (6)
- SEO (24)
- Google / Facebook / Pinterest / SNS (80)
- Tools (22)
最新评论
-
1455975567:
xuezhongyu01 写道wocan23 写道我想问下那个 ...
Mysql: LBS实现查找附近的人 (两经纬度之间的距离) -
xuezhongyu01:
wocan23 写道我想问下那个111.1是怎么得来的我也看不 ...
Mysql: LBS实现查找附近的人 (两经纬度之间的距离) -
18335864773:
试试 pageoffice 在线打开 PDF 文件吧. pag ...
jquery在线预览PDF文件,打开PDF文件 -
青春依旧:
opacity: 0.5; 个人喜欢这种方式!关于其他css特 ...
css透明度的设置 (兼容所有浏览器) -
July01:
推荐用StratoIO打印控件,浏览器和系统的兼容性都很好,而 ...
搞定网页打印自动分页问题
一、简介
py2exe是一个将python脚本转换成windows上的可独立执行的可执行程序(*.exe)的工具,这样,你就可以不用装python而在windows系统上运行这个可执行程序。
py2exe已经被用于创建wxPython,Tkinter,Pmw,PyGTK,pygame,win32com client和server,和其它的独立程序。py2exe是发布在开源许可证下的。
二、安装py2exe
从http://prdownloads.sourceforge.net/py2exe 下载并运行与你所安装的Python对应的py2exe版本的installer,这将安装py2exe和相应的例子;这些例子被安装在lib\site-packages\py2exe\samples目录下。
三、py2exe的用法
如果你有一个名为helloworld.py的python脚本,你想把它转换为运行在windows上的可执行程 序,并运行在没有安装python的 windows系统上,那么首先你应写一个用于发布程序的设置脚本例如mysetup.py,在其中的setup函数前插入语句 import py2exe 。
mysetup.py示例如下:
from distutils.core import setup import py2exe setup(console=["helloworld.py"])
如果显示错误提示的话 “ msvcp90.dll: no such file or directory”
请尝试下面的方法:
from distutils.core import setup import py2exe setup( console=["helloworld.py"], options = { "py2exe": { "dll_excludes": ["MSVCP90.dll"] } } )
然后按下面的方法运行mysetup.py: (dos: cmd => cd desktop => mysetup.py py2exe)
python mysetup.py py2exe
上面的命令执行后将产生一个名为dist的子目录,其中包含了helloworld.exe,python24.dll,library.zip这些文件。
如果你的helloworld.py脚本中用了已编译的C扩展模块,那么这些模块也会被拷贝在个子目录中,同样,所有的dll文件在运行时都是需要的,除了系统的dll文件。
dist子目录中的文件包含了你的程序所必须的东西,你应将这个子目录中的所有内容一起发布。
默认情况下,py2exe在目录dist下创建以下这些必须的文件:
1、一个或多个exe文件。
2、python##.dll。
3、几个.pyd文件,它们是已编译的扩展名,它们是exe文件所需要的;加上其它的.dll文件,这些.dll是.pyd所需要的。
4、一个library.zip文件,它包含了已编译的纯的python模块如.pyc或.pyo
上面的mysetup.py创建了一个控制台的helloword.exe程序,如果你要创建一个图形用户界的程序,那么你只需要将mysetup.py中的console=["helloworld.py"]替换为windows=["myscript.py"]既可。
py2exe一次能够创建多个exe文件,你需要将这些脚本文件的列表传递给console或windows的关键字参数。如果你有几个相关联的脚本,那么这是很有用的。
运行下面个命令,将显示py2exe命令的所有命令行标记。
python mysetup.py py2exe --help
Global options: --verbose (-v) run verbosely (default) --quiet (-q) run quietly (turns verbosity off) --dry-run (-n) don't actually do anything --help (-h) show detailed help message Options for 'py2exe' command: --optimize (-O) optimization level: -O1 for "python -O", -O2 for "python -OO", and -O0 to disable [default: -O0] --dist-dir (-d) directory to put final built distributions in (default is dist) --excludes (-e) comma-separated list of modules to exclude --dll-excludes comma-separated list of DLLs to exclude --ignores comma-separated list of modules to ignore if they are not found --includes (-i) comma-separated list of modules to include --packages (-p) comma-separated list of packages to include --compressed (-c) create a compressed zipfile --xref (-x) create and show a module cross reference --bundle-files (-b) bundle dlls in the zipfile or the exe. Valid levels are 1, 2, or 3 (default) --skip-archive do not place Python bytecode files in an archive, put them directly in the file system --ascii (-a) do not automatically include encodings and codecs --custom-boot-script Python file that will be run when setting up the runtime environment usage: setup_py2exe.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...] or: setup_py2exe.py --help [cmd1 cmd2 ...] or: setup_py2exe.py --help-commands or: setup_py2exe.py cmd --help
四、指定额外的文件
一些应用程序在运行时需要额外的文件,诸如配置文件、字体、位图。
如果在安装脚本中用data_files可选项指定了那些额外的文件,那么py2exe能将这些文件拷贝到dist子目录中。data_files应包含一个元组(target-dir, files)列表,其中的files是这些额外的文件的列表。
示例如下:
PythonCode: # mysetup.py
from distutils.core import setup import glob import py2exe setup(console=["helloworld.py"], data_files=[("bitmaps", ["bm/large.gif", "bm/small.gif"]), ("fonts", glob.glob("fonts\\*.fnt"))], )
说明:data_files选项将创建一个子目录dist\bitmaps,其中包含两个.gif文件;一个子目录dist\fonts,其中包含了所有的.fnt文件。
五、Windows NT services
你可以通过传递一个service关键字参数给setup函数来建造Windows NT services
,这个service参数的值必须是一个Python模块名(包含一service类)的列表。
示例如下:
PythonCode: # mysetup.py
from distutils.core import setup import py2exe setup(service=["MyService"])
所建造的可执行的service是可以通过在其后跟一定的命令行参数标记来自行安装和卸载的。你可以通过在这个可执行的service(exe)后跟一-help参数来得到更多的帮助。
六、COM servers
你可以通过传递一个com_server 关键字参数给setup函数来建造Windows NT services
,这个service参数的值必须是一个Python模块名(包含一个或多个COM server 类)的列表。
示例如下:
PythonCode: # mysetup.py
from distutils.core import setup import py2exe setup(com_server=["win32com.server.interp"])
默认情况下,DLL和EXE servers被建造,你不需要它们的话你可以简单的删除它们。
一个标准的py2exe setup文件编写
-*- coding: cp936 -*- from distutils.core import setup import py2exe includes = ["encodings", "encodings.*"] #要包含的其它库文件 options = {"py2exe": {"compressed": 1, #压缩 "optimize": 2, "ascii": 1, "includes":includes, "bundle_files": 1 #所有文件打包成一个exe文件 } } setup( options = options, zipfile=None, #不生成library.zip文件 console=[{"script": "hello.py", "icon_resources": [(1, "hello.ico")] }]#源文件,程序图标 )
新 版本已经可以打包为一个文件了,以前都是一堆dll,pyd的。具体的变化其实只有一个地方。就是options里增加bundle_files项,值为 1表示pyd和dll文件会被打包到exe文件中,且不能从文件系统中加载python模块;值为2表示pyd和dll文件会被打包到exe文件中,但是 可以从文件系统中加载python模块。另外setup中使用zipfile=None可以不生成library.zip。
例如原来 的:
from distutils.core import setup import py2exe includes = ["encodings", "encodings.*"] options = {"py2exe": { "compressed": 1, "optimize": 2, "includes": includes, } } setup( version = "0.1.0", description = "search panda", name = "search panda", options = options, windows=[{"script": "search.py", "icon_resources": [(1, "search.ico")] }], )
只需要改为:
from distutils.core import setup import py2exe includes = ["encodings", "encodings.*"] options = {"py2exe": { "compressed": 1, "optimize": 2, "includes": includes, "bundle_files": 1 } } setup( version = "0.1.0", description = "search panda", name = "search panda", options = options, zipfile=None, windows=[{"script": "search.py", "icon_resources": [(1, "search.ico")] }], )
比如,这里我打包以前的DelphiCode2HTML的
# -*- coding: gbk -*- from distutils.core import setup import py2exe includes = ["encodings", "encodings.*"] options = {"py2exe": {"compressed": 1, "optimize": 2, "ascii": 1, "includes":includes, "bundle_files": 1} } setup( options = options, zipfile=None, name = "HelloGuys.", description = "this is a py2exe test", windows=[{"script": "F:\我的程序\Python\CSDN Code Edit\Code2Html.py", "icon_resources": [(1, "F:\书籍\我的图标\图标xp\Convert.ico")] }] )
下面列出他的一些 options
keyword |
description |
list of "data" files that you are going to need to run your executable such as .pngs, .jpgs |
Py2exe extends Distutils setup keywords
In addition to the standard distutils setup keywords, the following py2exe keywords specify what and how to build.
keyword |
description |
console |
list of scripts to convert into console exes |
windows |
list of scripts to convert into GUI exes |
service |
list of module names containing win32 service classes |
com_server |
list of module names containing com server classes |
ctypes_com_server |
list of module names containing com server classes |
zipfile |
name of shared zipfile to generate; may specify a subdirectory; defaults to 'library.zip'. If zipfile is set to None , the files will be bundled within the executable instead of 'library.zip'. |
options |
dictionary { "py2exe": { "opt1": val1, "opt2": val2, ... } } |
The options dictionary of py2exe
The option keyword takes the following set of dictionary key: value pairs. The dictionary "key" names and the "value" types are listed in the table below.
key |
value |
unbuffered |
if true, use unbuffered binary stdout and stderr |
optimize |
string or int of optimization level (0, 1, or 2) 0 = don’t optimize (generate .pyc) 1 = normal optimization (like python -O) 2 = extra optimization (like python -OO) See http://docs.python.org/distutils/apiref.html#module-distutils.util for more info. |
includes |
list of module names to include |
packages |
list of packages to include with subpackages |
ignores |
list of modules to ignore if they are not found |
excludes |
list of module names to exclude |
dll_excludes |
list of dlls to exclude |
dist_dir |
directory in which to build the final files |
typelibs |
list of gen_py generated typelibs to include |
compressed |
(boolean) create a compressed zipfile |
xref |
(boolean) create and show a module cross reference |
bundle_files |
bundle dlls in the zipfile or the exe. Valid values for bundle_files are: 3 = don't bundle (default) 2 = bundle everything but the Python interpreter 1 = bundle everything, including the Python interpreter |
skip_archive |
(boolean) do not place Python bytecode files in an archive, put them directly in the file system |
ascii |
(boolean) do not automatically include encodings and codecs |
custom-boot-script |
Python file that will be run when setting up the runtime environment |
Example:
setup( windows=['trypyglet.py'], options={ "py2exe":{ "unbuffered": True, "optimize": 2, "excludes": ["email"] } } )
For more information enter the following at the python command line:
>>> from distutils.core import setup >>> help(setup)
注意 windows 的用法,他可以代替 console, 如果你要集成 wxpython 的时候,一定会用的 !
更多请查看 http://www.py2exe.org/index.cgi/ListOfOptions
如果程序中含有email类,并且压缩时出现类似 “ImportError: No module named multipart ” 的错误,你需要如下的设置:
1. 尝试将Lib下的email包,复制到当前文件夹中
2. 把['emai'] 放入includes中
3. 把['email']放入packages中
4. 继续运行py2exe
如:
from distutils.core import setup import py2exe includes = ["encodings", "encodings.*",'email'] options = {"py2exe": { "compressed": 1, "optimize": 2, "includes": includes, "bundle_files": 1, "packages": ['email'], "dll_excludes": ["MSVCP90.dll"] } } setup( version = "0.1.0", description = "3th", name = "For My Lover", options = options, zipfile=None, windows=[{"script": "love.py", "icon_resources": [(1, "roses.ico")] }], )
- py2exe-0.6.9.win32-py2.7.zip (167.2 KB)
- 下载次数: 12
评论
Errors occurred:
see the logfile 'XXX.log' for details
怎样让程序在关闭exe时不弹出这个提示?
不客气,共同进步~
发表评论
-
Python实例讲解 -- 接收邮件 (亲测)
2011-02-23 07:13 318511. 主要使用了 poplib 组件 # -*- ... -
Python实例讲解 -- 发送邮件带附件 (亲测)
2011-02-23 05:16 12045主要使用了 smtp 和 email 组件 # -*- ... -
文本输入控件wx.TextCtrl
2011-02-22 06:49 14316构造函数: wx.TextCtrl ... -
Python设置默认语言编码
2011-02-22 05:31 3068当python中间处理非ASCII编码时,经常会出现如下错误: ... -
Python实例讲解 -- wxpython 最小到托盘及欢迎图片
2011-02-15 00:59 8001需要注意的是,这里是托盘上的图标弹出菜单是覆盖了Creat ... -
Python实例讲解 -- tkinter canvas (设置背景图片及文字)
2011-02-14 22:17 44619先来一个绘图: from Tkinter import ... -
Python实例讲解 -- wxpython 基本的控件 (按钮)
2011-02-12 04:47 98845使用按钮工作 在wxPython 中有很多不同类型的 ... -
Python实例讲解 -- wxpython 基本的控件 (文本)
2011-02-12 04:20 43796使用基本的控件工作 wxPython 工具包提供了多 ... -
Python实例讲解 -- 操作数据库 附mysqldb win32 py2.7下载
2011-02-11 06:27 4511mysql是一个优秀的开源数据库,它现在的应用非常的广泛,因此 ... -
Python实例讲解 -- 解析xml
2011-02-11 05:38 8565doc.xml <?xml version=&q ... -
Python 列表 list 数组 array
2011-02-10 05:53 26912Python中的列表(list)类似于C#中的可变数组(Arr ... -
Python字符串的encode与decode
2011-02-10 05:32 3027首先要搞清楚,字符串 ... -
Python实例讲解 -- 认识wxpython 的 Frame
2011-02-09 23:21 8329简单小代码: #!/usr/bin/python # ... -
Python实例讲解 -- 获取本地时间日期(日期计算)
2011-02-09 05:40 418901. 显示当前日期: ... -
Python实例讲解 -- 定时播放 (闹钟+音乐)
2011-02-08 06:44 17470自己写的闹钟, 只可以播放wav格式的音频。 impo ... -
Python实例讲解 -- 图片处理
2011-02-08 02:57 17707虽然图像处理的最佳工 ... -
Python实例讲解 -- 磁盘文件的操作
2011-02-08 00:02 7097在文件夹里有六十多个RM格式的视频文件,我现在需要把它们的文件 ... -
wxPython中文教程 简单入门加实例
2011-01-27 21:49 66445wx.Window 是一个基类,许 ... -
新手如何运行第一个python程序
2011-01-19 03:36 21793不少新手朋友 遇到的 ... -
在Windows环境下用Editplus打造一个Python编辑调试环境
2011-01-19 00:21 6370Python有很多集成开发工具,商业的有 komodo, ...
相关推荐
py2exe使用方法
py2exe使用方法详解
unpy2exe.py可以从py2exe生成的exe中还原pyc文件, 适用于反编译py2exe程序。 程序使用pefile模块解析exe文件; 使用marshal模块生成pyc文件数据, 得到提取后的pyc文件。 其中还附带了py2exe_con.py和py2exe_w.py, ...
结合python2.7和py2exe软件; 安装后,直接使用讲程序写好后,在dos下运行,同时获取到可执行程序; 已验证可行;
最近有很多朋友对网上的py2exe使用教程看不懂,我在这里发布图文详解。 平台:python2.51 py2exe:0.69 for python2.5 这里以打包e://hello.py为例 第一步: 在e盘新建hello.py: helo.py代码如下: ----------------...
py2exe 能够把 Python script 转换成可以在windows上独立执行的(即不需安装Python)的exe程序(加上其它必需的运行时函数库)。
py2exe是一个将python脚本转换成windows上的可独立执行的可执行程序(*.exe)的工具,就可以不用装python而在windows系统上运行这个可执行程序。这里提供python 2.7, python3.3, python3.4 32位和64位的下载。
python转exe工具 -- python2.7版本的py2exe软件,可以将python转化为exe可执行文件。 py2exe是一个将python脚本转换成windows上的可独立执行的可执行程序(*.exe)的工具,这样,你就可以不用装python而在windows...
讲述py2exe的使用,并且简单讲解了里面一些常用参数的意义。
py转exe.py py转exe.py py转exe.py py转exe.pypy转exe.py py转exe.py py转exe.py py转exe.pypy转exe.py py转exe.py py转exe.py py转exe.pypy转exe.py py转exe.py py转exe.py py转exe.pypy转exe.py py转exe.py py转...
py2exe是一个将python脚本转换成windows上的可独立执行的可执行程序(*.exe)的工具,这样,你就可以不用装python而在windows系统上运行这个可执行程序。 py2exe已经被用于创建wxPython,Tkinter,Pmw,PyGTK,pygame,...
f2py.zip f2py.exe 文件 64 32位下载
1,py2exe-0.6.9.win32-py2.5.exe 2,python的exe可执行程序.doc 3,用python开发windows程序.doc 4,py2exe的简单使用.doc 5,py2exe打包python为exe.doc
py2exe-0.6.9.win32-py2.6.rar
介绍py2exe的使用,让大家更好地交流与学习!
利用py2exe将wxpython程序制作成exe文件的详细方法,含有简单例程以及参考链接资源
py2exe是将python脚本编译成exe文件的工具
最近上不了py2exe的主页,找了好久,最好用google才找到的64位版本的。
py2exe for python2.7:一款python脚本转换为exe程序的工具。py2exe是将python脚本编译成exe文件的工具,主要是setup.py的脚本中需要改动