`
willzh
  • 浏览: 296423 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

py2exe 把python脚本转成windows下可执行文件

阅读更多
py2exe是一个可以把python脚本转成windows下的可执行程序的模块。

py2exe扩展自disutils模块,由查看C:\Python25\Lib\site-packages\py2exe\__init__.py文件可知:
"""
builds windows executables from Python scripts

New keywords for distutils' setup function specify what to build:

    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'


py2exe options, to be specified in the options keyword to the setup function:

    unbuffered - if true, use unbuffered binary stdout and stderr
    optimize - string or int (0, 1, or 2)

    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 where to build the final files
    typelibs - list of gen_py generated typelibs to include (XXX more text needed)

Items in the console, windows, service or com_server list can also be
dictionaries to further customize the build process.  The following
keys in the dictionary are recognized, most are optional:

    modules (SERVICE, COM) - list of module names (required)
    script (EXE) - list of python scripts (required)
    dest_base - directory and basename for the executable
                if a directory is contained, must be the same for all targets
    create_exe (COM) - boolean, if false, don't build a server exe
    create_dll (COM) - boolean, if false, don't build a server dll
    bitmap_resources - list of 2-tuples (id, pathname)
    icon_resources - list of 2-tuples (id, pathname)
    other_resources - list of 3-tuples (resource_type, id, datastring)
"""
# py2exe/__init__.py

# 'import py2exe' imports this package, and two magic things happen:
#
# - the 'py2exe.build_exe' submodule is imported and installed as
#   'distutils.commands.py2exe' command
#
# - the default distutils Distribution class is replaced by the
# special one contained in this module.
#

__version__ = "0.6.8"

import distutils.dist, distutils.core, distutils.command, build_exe, sys

class Distribution(distutils.dist.Distribution):

    def __init__(self, attrs):
        self.ctypes_com_server = attrs.pop("ctypes_com_server", [])
        self.com_server = attrs.pop("com_server", [])
        self.service = attrs.pop("service", [])
        self.windows = attrs.pop("windows", [])
        self.console = attrs.pop("console", [])
        self.isapi = attrs.pop("isapi", [])
        self.zipfile = attrs.pop("zipfile", "library.zip")

        distutils.dist.Distribution.__init__(self, attrs)

distutils.core.Distribution = Distribution

distutils.command.__all__.append('py2exe')

sys.modules['distutils.command.py2exe'] = build_exe


简单的使用方式如下:
1. 创建一个python脚本hello.py
print 'hello'


2. 在同目录下创建一个setup.py脚本
from distutils.core import setup
import py2exe

setup(console=['hello.py']


3. 运行setup.py,通常参数是install,现在是py2exe
python setup.py py2exe


4. 你要的exe文件出现了
cd dist
./hello.exe


分享到:
评论

相关推荐

    python脚本打包可执行文件exe

    将自己写的python文件压缩成exe有两种方法: 1、使用pyinstaller 将自己写的python文件压缩成exe有两种方法: 1、使用pyinstaller step2:cd 到你的文件目录cd D:\py\python testcases\Slice step4:看结果...

    py2exe-0.6.9.win32-py2.7.zip

    py2exe是一个将python脚本转换成windows上的可独立执行的可执行程序(*.exe)的工具,这样,你就可以不用装python而在windows系统上运行这个可执行程序。 py2exe已经被用于创建wxPython,Tkinter,Pmw,PyGTK,pygame,win...

    py2exe安装文件

    py2exe是一个将python脚本转换成windows上的可独立执行的可执行程序(*.exe)的工具,就可以不用装python而在windows系统上运行这个可执行程序。这里提供python 2.7, python3.3, python3.4 32位和64位的下载。

    如何将Python脚本打包成可执行的exe文件#520表白代码

    如何将Python脚本打包成可执行的exe文件#520表白代码 我们开发的脚本一般都会用到一些第三方包,可能别人也需要用到我们的脚本,如果我们将我们的xx.py文件发给他,他是不能直接用的,他还需要安装python解释器,...

    unpy2exe.py - 反编译py2exe生成可执行文件的工具

    unpy2exe.py可以从py2exe生成的exe中还原pyc文件, 适用于反编译py2exe程序。 程序使用pefile模块解析exe文件; 使用marshal模块生成pyc文件数据, 得到提取后的pyc文件。 其中还附带了py2exe_con.py和py2exe_w.py, ...

    py2exe for python2.5

    py2exe是一个将python脚本转换成windows上的可独立执行的可执行程序(*.exe)的工具,这样,你就可以不用装python而在windows系统上运行这个可执行程序。

    py2exe-0.6.9.win32-py2.6

    py2exe是一个将python脚本转换成windows上的可独立执行的可执行程序(*.exe)的工具,这样,你就可以不用装python而在windows系统上运行这个可执行程序。 py2exe已经被用于创建wxPython,Tkinter,Pmw,PyGTK,pygame,...

    Python脚本文件打包成可执行文件的方法

    将Python脚本文件包装成可执行文件,其目的有二: 一则: 不需要依赖Python编译器就可以运行软件 二则: 不想让自己的源码公布出去 常用的工具有: py2exe、cx_freeze等 【工具:py2exe】 安装py2exe 安装该工具很简单: ...

    auto-py-to-exe-2.35.0,一个.py到.exe的转换器,使用简单的图形界面和Python中的PyInstall

    2、代码隐藏:Auto-py-to-exe允许将所有Python脚本和依赖项打包到一个独立的可执行文件中,使得用户无法直接访问或修改脚本。这有助于保护知识产权,并使代码更难以被非授权人员篡改。 3、可定制化选项:Auto-py-to-...

    赋予你的Python项目新生命:打包为独立可执行文件(exe)的简单步骤

    《赋予你的Python项目新生命:打包为独立可执行文件(exe)的简单步骤》 Python是一种解释型语言,通常不需要打包成可执行文件。但是,如果你想将你的Python代码部署到其他计算机上,或者想在没有安装Python解释器的...

    python生成可执行文件.exe的方法

    py2exe是一个将python脚本转换成windows上的可独立执行的可执行程序(*.exe)的工具,这样,你就可以不用装python而在windows系统上运行这个可执行程序。

    Python 脚本可自动执行 Simulia Abaqus 日常使用中的枯燥工作,从打开 GUI 到控制参数_Abaqus

    Python 脚本可自动执行 Simulia Abaqus 日常使用中的枯燥工作,从打开 GUI 到控制参数分析。 启动 Abaqus CAE open_abaqus.bat 启动 Abaqus CAE 并调用 open_abaqus.py 脚本。您可以为 bat 文件创建一个链接并将其...

    Python使用py2exe打包程序介绍

    py2exe是一个将python脚本转换成windows上的可独立执行的可执行程序(*.exe)的工具,这样,你就可以不用装python而在windows系统上运行这个可执行程序。 py2exe已经被用于创建wxPython,Tkinter,Pmw,PyGTK,pygame,win...

    python入门教程及python打包

    在Python中,可以使用打包工具将代码和依赖项打包成可执行的文件。下面是一些常见的Python打包工具: ...py2exe:py2exe是一个针对Windows平台的Python打包工具,可以将Python脚本和依赖项打包成Windows可执行文件。

    py2exe:一个distutils扩展,可从Python代码创建独立的Windows程序

    py2exe适用于Python 3 py2exe是distutils扩展,它允许从Python脚本构建独立的Windows可执行程序(32位和64位)。 支持官方开发周期中包含的Python版本(从3.6到3.9)。 py2exe可以构建控制台可执行文件和Windows...

    QPT - Python程序模块化封装工具(Py转EXE),快速将Python打包为EXE并添加CUDA、NoAVX等支持

    QPT - Python程序模块化封装工具(Py转EXE...QPT是一款可以“模拟”开发环境的多功能封装工具,最短只需一行命令即可将普通的Python脚本打包成EXE可执行程序,并选择性添加CUDA和NoAVX的支持,尽可能兼容更多的用户环境

    Python中py文件转换成exe可执行文件的方法

    今天闲着无事,写了一个小小的Python脚本程序,然后给同学炫耀的时候,发现每次都得拉着其他人过来看着自己的电脑屏幕,感觉不是很爽,然后我想着网上肯定有关于Python脚本转换成可执行文件的操作,事不宜迟,我就...

    hadoop实训课数据清洗py脚本(MapReduce python代码,可执行文件脚本,使用方法)

    可以作为大数据预处理的MapReduce代码的参考!!! -执行脚本文件: cd /home/hadoop/logfiles/ source format_run_2013_o5_30.sh source format_run_2013_o5_31.sh 执行我们的脚本文件,可以用source或者./

    python文件转为exe文件的方法及用法详解

     py2exe是一个将python脚本转换成windows上的可独立执行的可执行程序(*.exe)的工具,这样,你就可以不用装python而在windows系统上运行这个可执行程序。  py2exe已经被用于创建wxPython,Tkinter,Pmw,PyGTK,pygame...

Global site tag (gtag.js) - Google Analytics