Page 1 of 3 123 Last
  • Jump to page:
    #1
  1. Mini me.
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Location
    Cambridge, UK
    Posts
    783
    Rep Power
    13

    PY2EXE step-by-step guide


    People seem to have lots of problems with py2exe, I hope this helps:
    py2exe guide

    As this is fresh out off the press there maybe bugs - so any comments are appreciated.

    grim

    Comments on this post

    • shearn89 agrees : excellent!
    • pabloj agrees
    • BeetleJuice agrees : Good use of the KISS principle.
    • DomSau agrees : not bad
    • TextParser agrees : good one
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2004
    Location
    Bombay, India
    Posts
    159
    Rep Power
    12
    The step-by-step guide was very clear and simply put!

    Good one!!!!

    Subha
  4. #3
  5. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    Like it Grim!

    That is if you hadn't guessed by the fact that I've stuck this thread to the top of the forum [for the time being] . Anyway, one trivial thing I would add is an alternative way to get the command prompt/DOS prompt under Windows,

    Start > Run > Type 'command' or 'cmd'
    This isn't really that important... just a personal preference really and very handy little thing to know in general . Very cool!

    Mark.
    programming language development: www.netytan.com Hula

  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2004
    Location
    Lawrence, Kansas [KU]
    Posts
    1,559
    Rep Power
    15
    another thing to keep in mind is that you can get to Run Dialog very fast using: Window Button+R

    because using the mouse sucks.

    Comments on this post

    • Eeeman agrees : nice little tip for an amateur like myself
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2004
    Location
    Colorado, USA
    Posts
    68
    Rep Power
    10

    Another good py2exe resource


    This has helped me a number of times

    PY2exe wiki
    http://starship.python.net/crew/theller/moin.cgi/Py2Exe
  10. #6
  11. Mini me.
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Location
    Cambridge, UK
    Posts
    783
    Rep Power
    13
    Originally Posted by djjhouse
    This has helped me a number of times

    PY2exe wiki
    http://starship.python.net/crew/theller/moin.cgi/Py2Exe
    Yep - everything you need is already described on the official py2exe website and wiki. But - based on the number of forum posts it is clear that people don't get it

    My aim was to illustrate few basics such as:
    * Python code is stored as modules and they are text files
    * Setup.py is separate from the module you want to compile
    * Create a workspace directory
    * Use a DOS box to run Python


    These seem to be the things that first timers don't quite get and yet the tools they want to use assume these things are already understood.

    grimey
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2004
    Location
    Bimingham,AL
    Posts
    68
    Rep Power
    11

    Using Py2exe with Python Imaging Library (PIL )


    Using Py2exe with Python Imaging Library (PIL )

    Creating standalone windows executables on widows using is py2exe is pretty straight forward . But you might sometime run into unexpected problems like
    You might get the follwing errors while running the exe file created by the py2exe


    1 . LookupError: no codec search functions registered: can't find encodingsolution : explicitly include the encodings package:

    like this : python setup.py py2exe -p encodings

    Un located modules *are* normal. A lot of modules have conditional
    imports of other modules that they don't really *need*. This means
    py2exe tries to include them in case they are needed. This sometimes
    means you have more modules than you really need - and also reports of
    modules that can't be found.

    2 . Include the PIL switch on the py2exe line
    The py2exe line needs to be:
    python setup.py py2exe -p encodings –pPIL

    It worked for me even without that switch use that in case u run into problems .

    3 . File "Image.pyc", line 1571, in open
    IOError: cannot identify image file

    Solution : In order to make PIL and PY2EXE work together all libraries of PIL need to be imported explicitly such as:

    import Image
    import BmpImagePlugin # if you are using bitmaps
    Import JpgImagePlugin # if you are dealing with jpg images

    So forth ..
    Note : These explicit imports may not be necessary if you are running the python script directly but are needed if you are running the exe file created by py2exe .

    Comments on this post

    • pabloj agrees
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2005
    Posts
    54
    Rep Power
    11
    awesome man
  16. #9
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2005
    Posts
    7
    Rep Power
    0
    you legend! i've been trying to get py2exe to work all day!
  18. #10
  19. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2005
    Location
    OH
    Posts
    12
    Rep Power
    0
    This may be a dumb question, but is there a way to make an installer for the files generated by py2exe?
  20. #11
  21. Mini me.
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Location
    Cambridge, UK
    Posts
    783
    Rep Power
    13
    Originally Posted by mulciber
    This may be a dumb question, but is there a way to make an installer for the files generated by py2exe?
    Not a dumb question at all

    I use the excellent INNO Setup which seems to handle everything I need.

    grim
  22. #12
  23. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2005
    Location
    OH
    Posts
    12
    Rep Power
    0
    Excellent. I tried it using the example setup.py that came with py2exe for use with INNO and it worked almost perfectly except for a dll that somehow didn't get linked. I have to investigate further for what may have happened, it was msvcr71.dll. Thanks for the tip and clean tut.
  24. #13
  25. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2005
    Posts
    611
    Rep Power
    65

    Smile


    I have modified Paul Hardwick's code when using Py2Exe with wxPython to avoid the codec LookupError when you run the exe file.
    Code:
    # run this code to create a windows exe file
    # save in the working directory where your code file is
    # and run the program from there
    from distutils.core import setup
    import py2exe
    import sys
    
    sys.argv.append("py2exe")
    
    # usually needed for wxPython code to prevent the
    # "LookupError: no codec search functions registered" when you run the exe
    opt = {"py2exe": {"packages": ["encodings"]}}
    
    # insert your own code filename here ...
    setup(options = opt, windows = [{"script": 'myCodeFile.py'}])
  26. #14
  27. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2004
    Location
    Colorado, USA
    Posts
    68
    Rep Power
    10

    FYI--new py2exe version released --0.6.2


    The new version has a nifty option that can allow you to create a fast standalone executable. Other installer packages usually unzip the exe into a temp dir and run it from there. The py2exe implementation does not.

    You can bundle all of the files into a "Library.zip" and have a small executable, or bundle all into one .exe .

    To create one large exe,simply add the line
    Code:
    zipfile=None
    to your setup.py.
    Then from the command line, call
    Code:
    python setup.py py2exe --bundle 1
    The bundle 2 option, also does a little less bundling.
  28. #15
  29. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2005
    Posts
    611
    Rep Power
    65

    Smile


    I found this little gem in
    C:\Python24\Lib\site-packages\py2exe\samples\singlefile\gui\setup.py
    on my computer after installing version 6.3 of Py2Exe. It creates a single executable file from wxPython code. I modified it slightly, added more user comments and called it wxPython2Exe.py .
    Code:
    # Py2Exe version 6.3 setup file for wxPython GUI programs.
    # Creates a single exe file.
    # It's easiest to add this wxPython2Exe.py file into the same
    # folder with the source file and an optional iconfile like "icon.ico"
    # (if you add your own icon file, remove the comment in front of icon_resources).
    # Simply change the filename to whatever you called your source file.
    # Optionally edit the version info and add the name of your icon file.
    # Now run wxPython2Exe.py ...
    # Two subfolders will be created called build and dist.
    # The dist folder contains your .exe file, MSVCR71.dll and w9xpopen.exe
    # Your .exe file contains your code, all neded modules and the Python interpreter.
    # The MSVCR71.dll can be distributed, but is often already in the system32 folder.
    
    from distutils.core import setup
    import py2exe
    import sys
    
    
    # enter the filename of your wxPython code file to compile ...
    filename = "wxCalc1.py"
    
    # ... this creates the filename of your .exe file in the dist folder
    if filename.endswith(".py"):
        distribution = filename[:-3]
    elif filename.endswith(".pyw"):
        distribution = filename[:-4]
    
    
    # if run without args, build executables in quiet mode
    if len(sys.argv) == 1:
        sys.argv.append("py2exe")
        sys.argv.append("-q")
    
    class Target:
        def __init__(self, **kw):
            self.__dict__.update(kw)
            # for the versioninfo resources, edit to your needs
            self.version = "0.6.3"
            self.company_name = "My Company"
            self.copyright = "no copyright"
            self.name = "WxPython Calculator"
    
    ################################################################
    # The manifest will be inserted as resource into your .exe.  This
    # gives the controls the Windows XP appearance (if run on XP ;-)
    #
    # Another option would be to store it in a file named
    # test_wx.exe.manifest, and copy it with the data_files option into
    # the dist-dir.
    #
    manifest_template = '''
    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
    <assemblyIdentity
        version="5.0.0.0"
        processorArchitecture="x86"
        name="%(prog)s"
        type="win32"
    />
    <description>%(prog)s Program</description>
    <dependency>
        <dependentAssembly>
            <assemblyIdentity
                type="win32"
                name="Microsoft.Windows.Common-Controls"
                version="6.0.0.0"
                processorArchitecture="X86"
                publicKeyToken="6595b64144ccf1df"
                language="*"
            />
        </dependentAssembly>
    </dependency>
    </assembly>
    '''
    
    RT_MANIFEST = 24
    
    # description is the versioninfo resource
    # script is the wxPython code file
    # manifest_template is the above XML code
    # distribution will be the exe filename
    # icon_resource is optional, remove any comment and give it an iconfile you have
    #   otherwise a default icon is used
    # dest_base will be the exe filename
    test_wx = Target(
        description = "A GUI app",
        script = filename,
        other_resources = [(RT_MANIFEST, 1, manifest_template % dict(prog=distribution))],
        #icon_resources = [(1, "icon.ico")],
        dest_base = distribution)
    
    ################################################################
    
    setup(
        options = {"py2exe": {"compressed": 1,
                              "optimize": 2,
                              "ascii": 1,
                              "bundle_files": 1}},
        zipfile = None,
        windows = [test_wx],
        )

    Comments on this post

    • netytan agrees : Nice; not a Py2exe fan but its cool :)
    Last edited by Dietrich; January 21st, 2006 at 02:59 PM.
Page 1 of 3 123 Last
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo