Differences between revisions 2 and 3
Revision 2 as of 2003-11-01 01:27:58
Size: 396
Editor: dclient80-218-75-60
Comment: improved looking
Revision 3 as of 2003-11-06 02:26:14
Size: 956
Editor: dclient217-162-156-158
Comment:
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
'''Question:''' Is it possible to specify options like "--includes" programaticaly in the setup()
function?
= Avoid sys.argv to pass options to py2exe =
Many users write a special setup script for py2exe that simply can be run to build the exe, without the need to specify command line options by hand, each time. That means that "includes", "excludes" options etc have to be passed in some way to py2exe.
Line 4: Line 4:
'''Answer:'''
Yes, distutils has such a functionality, although it seems to be undocumented. You can create a dictionary like this:
The {{{setup()}}} function accepts a {{{options}}} keyword argument, containing a dictionary with the options. This is supperior to appending options to {{{sys.argv}}} as the transformation of the data to a string and back is avoided as well as mutiple {{{setup()}}} calls per file are possible.

Note that the long name of options has to be used and '-' in the command line options become '_' in the dictionary (e.g. "dist-dir" becomes "dist_dir").
Line 8: Line 9:
opts = {"py2exe": {"includes": "mod1, mod2"}} opts = {
    
"py2exe": {
        
"includes": "mod1, mod2",
        "dist_dir": "bin",
    
}
}
Line 11: Line 17:
and pass it to the setup script: And pass it to the setup script:
Line 14: Line 20:
setup(...
   options = opts,
     )
setup(
    options = opts,
    ...
)

Avoid sys.argv to pass options to py2exe

Many users write a special setup script for py2exe that simply can be run to build the exe, without the need to specify command line options by hand, each time. That means that "includes", "excludes" options etc have to be passed in some way to py2exe.

The setup() function accepts a options keyword argument, containing a dictionary with the options. This is supperior to appending options to sys.argv as the transformation of the data to a string and back is avoided as well as mutiple setup() calls per file are possible.

Note that the long name of options has to be used and '-' in the command line options become '_' in the dictionary (e.g. "dist-dir" becomes "dist_dir").

opts = {
    "py2exe": {
        "includes": "mod1, mod2",
        "dist_dir": "bin",
    }
}

And pass it to the setup script:

setup(
    options = opts,
    ...
)

PassingOptionsToPy2Exe (last edited 2008-07-08 11:27:43 by localhost)