10

I can set the final dist directory of py2exe using the command line:

python setup.py py2exe -d "my/dist/dir"

but I can't seem to set the file to use for the interim build directory. I've taken a brief look at the source, but unless I am missing something there doesn't appear to be any way to do it.

Casey
  • 12,070
  • 18
  • 71
  • 107

3 Answers3

10

Any option that you can set on the command line you can set either through a setup.cfg file or in your setup.py file.

-d is a shortcut for --dist-dir which you can add to the py2xe dict in the dictionary passed to the options keyword param of setup as 'dist_dir':

from distutils.core import setup
import py2exe

# equivalent command line with options is:
# python setup.py py2exe --compressed --bundle-files=2 --dist-dir="my/dist/dir" --dll-excludes="w9xpopen.exe"
options = {'py2exe': {
           'compressed':1,  
           'bundle_files': 2, 
           'dist_dir': "my/dist/dir"
           'dll_excludes': ['w9xpopen.exe']
           }}
setup(console=['myscript.py'], options=options)

You could also put setup.cfg next to your setup.py file:

[py2exe]
compressed=1
bundle_files=2 
dist_dir=my/dist/dir
dll_excludes=w9xpopen.exe

The build directory (--build-base) is an option of the build command so you can add it to one of the config files (or the setup.py) as:

[build]
build_base=my/build/dir
lambacck
  • 9,768
  • 3
  • 34
  • 46
  • This doesn't completely work though. I can specify the `dist` dir just as you suggest, but `py2exe` also uses an intermediate `build` directory that I can't seem to change. – Casey May 26 '11 at 15:38
  • 1
    Oops. Missed the build dir part :) – lambacck May 26 '11 at 19:30
  • No problem. I've actually dug into the py2exe source and might make some modifications myself here. When I get a few extra hours. – Casey May 27 '11 at 00:20
  • I added the info for setting the build directory btw (in case that wasn't obvious). – lambacck May 27 '11 at 01:29
6

To clarify on lambacck's answer, this works on the latest vanilla py2exe:

options = {'build': {'build_base': 'my/build/dir'},
           'py2exe': {
           'compressed':1,  
           'bundle_files': 2, 
           'dist_dir': "my/dist/dir"
           'dll_excludes': ['w9xpopen.exe']
          }}
vostok4
  • 61
  • 1
  • 4
0

Ran into the same problem as Casey. We have a build system I'd like to conform to when generating a .exe with py2exe.

However I don't think lambacck's answer works. 'build_base' is not an option of py2exe

To prove it run this: python setup.py --help py2exe

This should list all the options for py2exe. 'build_base' is not listed in there.

I'm using py2exe 0.6.9

I could be wrong, but it sounds like someone needs to send a patch to whoever maintains this project. It's on SourceForge and hasn't been touch since 2008.

Bokeh
  • 1,013
  • 7
  • 9