Differences between revisions 2 and 21 (spanning 19 versions)
Revision 2 as of 2004-08-10 17:25:14
Size: 3796
Editor: argos
Comment: shorter variant
Revision 21 as of 2015-04-03 13:38:35
Size: 559
Editor: Adam77833
Comment:
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
The "extending" example that comes with Py2Exe shows a nicely integrated approach for using Inno Setup to create single file executables. This example isn't so nicely integrated, but it uses [http://nsis.sourceforge.net NSIS] instead of Inno Setup in case you prefer that.

Drop a copy of this script in your source directory alongside setup.py and modify the first two lines. The first points to py2exe's output directory and the second is the name of the executable in that directory as well as the name of the executable that NSIS will create. You can also select compression behavior - NSIS' LZMA compression (based on [http://www.7-zip.com 7-Zip]) is pretty impressive - wxPython applications start at about 3.5 - 4 MB instead of 10 - 12 MB. Compression may slow startup time for your executable somewhat.

Once you've built your executable with py2exe, then compile the installer script with NSIS and an executable will be created in the same folder as the script. When run, that single file executable will expand the original executable created by py2exe along with all the dll, pyd, and data files for your application into a temporary directory and run it. When your application exits, the temp folder will be deleted automatically.

Command line parameters for your executable are not supported.

The executables produced have only been tested on Windows XP. Please update this page if you try them on other platforms.

[mailto:jimmy@retzlaff.com&subject=Single%20File%20Python%20Executables Jimmy Retzlaff]
----
'''setup.nsi:'''
{{{
!define py2exeOutputDirectory 'dist\Calculator'
!define exe 'calculator.exe'

; Comment out the "SetCompress Off" line and uncomment
; the next line to enable compression. Startup times
; will be a little slower but the executable will be
; quite a bit smaller
SetCompress Off
;SetCompressor lzma

Name 'Calculator'
OutFile ${exe}
SilentInstall silent
;Icon 'icon.ico'

Section
    InitPluginsDir
    SetOutPath '$PLUGINSDIR'
    File '${py2exeOutputDirectory}\*.*'

    GetTempFileName $0
    DetailPrint $0
    Delete $0
    StrCpy $0 '$0.bat'
    FileOpen $1 $0 'w'
    FileWrite $1 '@echo off$\r$\n'
    StrCpy $2 $TEMP 2
    FileWrite $1 '$2$\r$\n'
    FileWrite $1 'cd $PLUGINSDIR$\r$\n'
    FileWrite $1 '${exe}$\r$\n'
    FileClose $1
    nsExec::Exec $0
    Delete $0
SectionEnd
}}}

The version above seems to work fine on Win9x. Even with the batch file that is lauched (and DOS boxes do not close automaticaly, by default, on those OS). The startup time of a wxPython app with lzma compression becomes very long (1+ minute) on a machinne with 64MB RAM and a Pentium 200MHz, but it's usable on faster machines that are common today ;-)

The shorter version below works fine too. Tough it does not start he application in the directory it was extracted to ({{{os.curdir}}} probably points to the location of the installer; to be verified). But the application can find out its own location by using {{{os.path.dirname(sys.argv[0])}}}.

I also added a "/r" so that subdirectories are also packed into the installer as i tend to keep images and other data as external files in a subdir, even with py2exe.

''cliechti''

'''setup.nsi:'''
{{{
!define py2exeOutputDirectory 'dist\Calculator'
!define exe 'calculator.exe'
 
; Comment out the "SetCompress Off" line and uncomment
; the next line to enable compression. Startup times
; will be a little slower but the executable will be
; quite a bit smaller
SetCompress Off
;SetCompressor lzma

Name ${exe}
OutFile ${exe}
SilentInstall silent
;Icon 'icon.ico'

Section
    InitPluginsDir
    SetOutPath '$PLUGINSDIR'
    File /r '${py2exeOutputDirectory}\*.*'
    nsExec::Exec $PLUGINSDIR\${exe}
SectionEnd
}}}
Hi a lot of. My name is Eboni an individual can call me whatever you decide to like. Credit authorising is where my primary income obtain from. Iowa is where we've been living for as well as my family loves it's. One of this things she loves most is to [[http://Www.Encyclopedia.com/searchresults.aspx?q=play+badminton|play badminton]] and she'll be starting something else along utilizing. Check out my website here: http://garciniaoptimas.org/<<BR>><<BR>>
<<BR>><<BR>>
Feel free to visit my web site: [[http://garciniaoptimas.org/|garcinia optima scam]]

Hi a lot of. My name is Eboni an individual can call me whatever you decide to like. Credit authorising is where my primary income obtain from. Iowa is where we've been living for as well as my family loves it's. One of this things she loves most is to play badminton and she'll be starting something else along utilizing. Check out my website here: http://garciniaoptimas.org/<<BR>><<BR>>

Feel free to visit my web site: garcinia optima scam

SingleFileExecutable (last edited 2015-04-03 16:23:23 by JimmyRetzlaff)