ant-python

SetupPy2exe

Description

Create a setup.py file designed to be used with py2exe. This task extends the task Setup and adds some special flags required for a py2exe setup.py file.

Note

Note that this task only creates the setup.py file. Use the task Build to create a Python distribution from a setup.py file.

Parameters

See Setup for the base attributes.

Attribute Description Required
tkinter Whether to include Tkinter data files and DLLs. no, defaults to false
matplotlib Whether to include matplotlib data files. Note that it requires matplotlib library to be installed. no, defaults to false
wxPython Whether to include wxPython data files and DLLs. no, defaults to false
lxml Whether to include lxml packages. no, defaults to false
skipArchive Whether to skip placing Python bytecode files in an archive. no, defaults to false

Parameters specified as nested elements

See Setup for the base nested elements.

includes, excludes and DLL excludes

These three nested elements (<include>, <exclude> and <dllExclude>) allow to respectively include, exclude certain package(s) or exclude certain DLL from the distribution. Both element only takes one attribute (name) specifying the module or the full path of the DLL to exclude. See py2exe documentation for more explanations.

console and window

Specify which module is the entry point for the exe application. The element <console> specify a module that will be executed from a command line prompt, whereas the element <window> specify a GUI application. Several modules can be defined if a distribution requires multiple exe applications to be created by py2exe. Both nested elements take two attributes:

Attribute Description Required
script Full path to the Python module yes
icon Full path to the icon associated with the application. no

Examples

Here is an example of the <setup> task for the package foo.bar containing one Python module hello.py and one data file hello.txt. A exe application will be created from the Python module hello.py. It requires Tkinter to be displayed.:

<setup-py2exe
        name="Foo"
        dir="${path.to.package}"
        manifest="true"
        version="1.0"
        url="http://foobar.com"
        author="John Doe"
        authorEmail="john@foobar.com"
        shortDescription="Test package"
        longDescription="Example for the ant task setup"
        license="GPL"
        tkinter="true">
    <classifier name="Development Status :: 4 - Beta" />
    <classifier name="Programming Language :: Python" />

    <require name="numpy" op=">=" version="1.6" />

    <window script="${path.to.package}/foo/bar/hello.py" />
</setup-py2exe>

Running this task will generate the following setup.py. Note that ${path.to.package} would be replaced by the actual path.:

#!/usr/bin/env python
# Created by antpython

from distutils.core import setup
import py2exe

setup(
   name='Foo',
   version='1.0',
   url='http://foobar.com',
   author='John Doe',
   author_email='john@foobar.com',
   packages=['foo', 'foo.bar'],
   package_data={'foo.bar': ['hello.txt']},
   description='Test package',
   long_description='Example for the ant task setup',
   classifiers=['Development Status :: 4 - Beta', 'Programming Language :: Python'],
   license='GPL',
   data_files=[('foo/bar', ['${path.to.package}/foo/bar/hello.txt'])],
   install_requires=['numpy>=1.6'],
   windows=[{"script": '${path.to.package}/foo/bar/hello.py'}],
   options={'py2exe': {'ascii': False, 'packages': ['foo', 'foo.bar'], 'excludes': ['matplotlib'], 'dll_excludes': []}},
)