views:

955

answers:

5

Hello, is there a way to create a standalone .exe from a python script. Executables generated with py2exe can run only with pythonXX.dll. I'd like to obtain a fully standalone .exe which does not require to install the python runtime library. It looks like a linking problem but using static library instead the dynamic one and it would be also useful to apply a strip in order to remove the unused symbols.

Any idea ?

Thanks.

Alessandro

+1  A: 

This is not the best way to do it, but you might consider using executable SFX Archive with both the .exe and .dll files inside, and setting it to execute your .exe file when it's double clicked.

Aziz
+11  A: 

You can do this in the latest version of py2exe...
Just add something like the code below in your setup.py file (key part is 'bundle_files': 1).

To include your TkInter package in the install, use the 'includes' key.

distutils.core.setup(
      windows=[
            {'script': 'yourmodule.py',
             'icon_resources': [(1, 'moduleicon.ico')]
            }
      ],
      zipfile=None,
      options={'py2exe':{
                         'includes': ['tkinter'],
                         'bundle_files': 1
                        }
      }
  )
jcoon
The solution is working well but what about the inclusion of tkinter in the exe?The executable crashes if I move it out the dist directory but it works well inside dist where "tcl" dir is present.
alexroat
ooops, sorry, with option 'bundle_files':1 it is not working both launching exe from dist directory or from outside.Is there a way to include tcl libraries in the exe too ?Thanks.
alexroat
I've updated the options variable to show you how to include other packages.
jcoon
+4  A: 

Due to how Windows' dynamic linker works you cannot use the static library if you use .pyd or .dll Python modules; DLLs loaded in Windows do not automatically share their symbol space with the executable and so require a separate DLL containing the Python symbols.

Ignacio Vazquez-Abrams
+1  A: 

Another solution is to create a single exe with python and all your dependencies installed inside of it, including the python.dll. There's a bit of magic in the wrapper, but it just works. The details are here:

http://code.google.com/p/pylunch/downloads/detail?name=PyLunch-0.2.pdf

Mark Ramm
+2  A: 

If your purpose of having a single executable is to ease downloading/emailing, etc., I've solved this by bundling the py2exe output using Inno Setup. This is actually better than having a single executable, because rather than providing an executable file that can be dropped into some directory, a well behaved Windows application will provide an uninstaller, show up in the Add/Remove Programs applet, etc. Inno handles all this for you.

Ryan Ginstrom