Differences between revisions 6 and 10 (spanning 4 versions)
Revision 6 as of 2008-07-08 11:27:43
Size: 3607
Editor: localhost
Comment: converted to 1.6 markup
Revision 10 as of 2012-10-05 04:21:07
Size: 5713
Editor: 24-217-160-200
Comment: Add details for how to package GTK+ SVG support, especially loaders.cache update.
Deletions are marked like this. Additions are marked like this.
Line 26: Line 26:

Line 33: Line 31:
import os

# Find GTK+ installation path
__import__('gtk')
m = sys.modules['gtk']
gtk_base_path = m.__path__[0]
Line 49: Line 53:
                      'includes': 'cairo, pango, pangocairo, atk, gobject',                       # Optionally omit gio, gtk.keysyms, and/or rsvg if you're not using them
'includes': 'cairo, pango, pangocairo, atk, gobject, gio, gtk.keysyms, rsvg',
Line 55: Line 60:
                   'readme.txt'                    'readme.txt',
                   # If using GTK+'s built in SVG support, uncomment these
                   #os.path.join(gtk_base_path, '..', 'runtime', 'bin', 'gdk-pixbuf-query-loaders.exe'),
                   #os.path.join(gtk_base_path, '..', 'runtime', 'bin', 'libxml2-2.dll'),
Line 59: Line 67:
run setup.py py2exe. You'll get a warning:
Line 60: Line 69:

run setup.py py2exe. You'll get a warning:
Line 68: Line 75:
Once that's done, '''you'll need to copy the etc, lib and share directories from your GTK+ install
(''not'' the pygtk install) to the dist dir py2exe created.''' Optionaly,
you can clean the share\locale dir to include only the locales you need for GTK+. Same thing for
share\themes (I left both Default and MS-Windows). 
Once that's done, '''you'll need to copy the etc, lib and share directories from your GTK+ install  (''not'' the pygtk install) to the dist dir py2exe created.''' Optionaly,  you can clean the share\locale dir to include only the locales you need for GTK+. Same thing for share\themes (I left both Default and MS-Windows).
Line 73: Line 77:
If you are using kiwi, you will also have to copy the ''contents'' of the (''path to python'')/share/kiwi directory
(and (''path to python'')/share/gazpacho, if you used gazpacho) to the dist dir. And you will have
to create an empty 'kiwi' directory in the dist/pixmaps directory that you just copied there.
(note: I have not tested kiwi with the Innosetup installer, but if you try it and it works edit
this page and remove this note :) )
 * it seems that from lib/ only all the *.dlls in the subtree are needed, and from share/ only themes/ and locale/. saves lots of space
Line 79: Line 79:
Note you'll want to set the working directory (Start in:) for any shortcut you create
to the application directory containing the executable.
If you are using [[http://library.gnome.org/devel/pygtk/stable/class-gtkbuilder.html|GtkBuilder]] and later versions of GTK+ and PyGTK, you may get the following error message:

{{{
Y:\my_handytool\dist\library.zip\gtk\_gtk.py:10: RuntimeWarning: tp_compare didn't return -1 or -2 for exception
ImportError: could not import gio
ImportError: could not import gio
Traceback (most recent call last):
  File "my_handytool.py", line 88, in <module>
  File "my_handytool.py", line 75, in __init__
AttributeError: 'module' object has no attribute 'Builder'
}}}
This issue can be resolved by [[http://permalink.gmane.org/gmane.comp.python.py2exe/3889|adding the 'gio' module]] to the py2exe includes option in the setup.py file:

{{{
--- setup.py.org 2010-11-13 22:35:20.000000000 +0100
+++ setup.py 2010-11-13 20:26:02.000000000 +0100
@@ -14,7 +14,7 @@
     options = {
         'py2exe': {
             'dist_dir':'dist',
- 'includes': 'cairo, pango, pangocairo, atk, gobject',
+ 'includes': 'cairo, pango, pangocairo, atk, gobject, gio',
             }
         },
}}}
If you are using kiwi, you will also have to copy the ''contents'' of the (''path to python'')/share/kiwi directory (and (''path to python'')/share/gazpacho, if you used gazpacho) to the dist dir. And you will have to create an empty 'kiwi' directory in the dist/pixmaps directory that you just copied there. (note: I have not tested kiwi with the Innosetup installer, but if you try it and it works edit this page and remove this note :) )

Note you'll want to set the working directory (Start in:) for any shortcut you create to the application directory containing the executable.
Line 83: Line 109:
Line 111: Line 138:
; If you are using GTK's built-in SVG support, uncomment the following line.
;Filename: {cmd}; WorkingDir: "{app}"; Parameters: "/C gdk-pixbuf-query-loaders.exe > lib/gdk-pixbuf-2.0/2.10.0/loaders.cache"; Description: "GDK Pixbuf Loader Cache Update"; Flags: nowait runhidden
Line 113: Line 142:
This Recipe has been tested with:
Line 114: Line 144:
This Recipe has been tested with:
 
* [[http://www.microsoft.com/|Windows XP SP2]]
 
* [[http://www.python.org/download/|Python 2.4.3]]
 
* [[http://gladewin32.sourceforge.net/modules/wfdownloads/|gtk-win32 2.8.14-rc1]]
  * [[http://www.mapr.ucl.ac.be/~gustin/win32_ports/pygtk.html|pycairo 1.0.2-1]]
  * [[http://www.mapr.ucl.ac.be/~gustin/win32_ports/pygtk.html|pygtk 2.8.4-1]]
 
* [[http://www.async.com.br/projects/kiwi/|kiwi 1.9.20]] ''optional''
  * [[http://www.py2exe.org/|py2exe 0.6.5]]
 
* [[http://www.jrsoftware.org/isinfo.php|Inno Setup 5.1.6]]
 * [[http://www.microsoft.com/|Windows XP SP2 and Windows 7 Ultimate x64]]
* [[http://www.python.org/download/|Python 2.4.3 and Python 2.7.2]]
* [[http://gladewin32.sourceforge.net/modules/wfdownloads/|gtk-win32 2.8.14-rc1]]
 * [[http://www.mapr.ucl.ac.be/~gustin/win32_ports/pygtk.html|pycairo 1.0.2-1]]
 * [[http://www.mapr.ucl.ac.be/~gustin/win32_ports/pygtk.html|pygtk 2.8.4-1 and 2.24.8]]
* [[http://www.async.com.br/projects/kiwi/|kiwi 1.9.20]] ''optional''
 * [[http://www.py2exe.org/|py2exe 0.6.5 and 0.6.9]]
* [[http://www.jrsoftware.org/isinfo.php|Inno Setup 5.1.6 and 5.4.3]]

create your handytool.py:

import sys
import pygtk
if not sys.platform == 'win32':
    pygtk.require('2.0')
import gtk

from mainwindow import MainWindow

if __name__ == '__main__':
    # enable threading
    gtk.threads_init()
    gtk.threads_enter()

    # create the main window
    myapp = MainWindow()

    # start the program loop
    gtk.main()

    # cleanup
    gtk.threads_leave()

create your setup.py file:

from distutils.core import setup
import py2exe
import os

# Find GTK+ installation path
__import__('gtk')
m = sys.modules['gtk']
gtk_base_path = m.__path__[0]

setup(
    name = 'handytool',
    description = 'Some handy tool',
    version = '1.0',

    windows = [
                  {
                      'script': 'handytool.py',
                      'icon_resources': [(1, "handytool.ico")],
                  }
              ],

    options = {
                  'py2exe': {
                      'packages':'encodings',
                      # Optionally omit gio, gtk.keysyms, and/or rsvg if you're not using them
                      'includes': 'cairo, pango, pangocairo, atk, gobject, gio, gtk.keysyms, rsvg',
                  }
              },

    data_files=[
                   'handytool.glade',
                   'readme.txt',
                   # If using GTK+'s built in SVG support, uncomment these
                   #os.path.join(gtk_base_path, '..', 'runtime', 'bin', 'gdk-pixbuf-query-loaders.exe'),
                   #os.path.join(gtk_base_path, '..', 'runtime', 'bin', 'libxml2-2.dll'),
               ]
)

run setup.py py2exe. You'll get a warning:

The following modules appear to be missing
['gdk', 'ltihooks']

Ignore it ;)

Once that's done, you'll need to copy the etc, lib and share directories from your GTK+ install (not the pygtk install) to the dist dir py2exe created. Optionaly, you can clean the share\locale dir to include only the locales you need for GTK+. Same thing for share\themes (I left both Default and MS-Windows).

  • it seems that from lib/ only all the *.dlls in the subtree are needed, and from share/ only themes/ and locale/. saves lots of space

If you are using GtkBuilder and later versions of GTK+ and PyGTK, you may get the following error message:

Y:\my_handytool\dist\library.zip\gtk\_gtk.py:10: RuntimeWarning: tp_compare didn't return -1 or -2 for exception
ImportError: could not import gio
ImportError: could not import gio
Traceback (most recent call last):
  File "my_handytool.py", line 88, in <module>
  File "my_handytool.py", line 75, in __init__
AttributeError: 'module' object has no attribute 'Builder'

This issue can be resolved by adding the 'gio' module to the py2exe includes option in the setup.py file:

--- setup.py.org        2010-11-13 22:35:20.000000000 +0100
+++ setup.py    2010-11-13 20:26:02.000000000 +0100
@@ -14,7 +14,7 @@
     options = {
         'py2exe': {
             'dist_dir':'dist',
-            'includes': 'cairo, pango, pangocairo, atk, gobject',
+            'includes': 'cairo, pango, pangocairo, atk, gobject, gio',
             }
         },

If you are using kiwi, you will also have to copy the contents of the (path to python)/share/kiwi directory (and (path to python)/share/gazpacho, if you used gazpacho) to the dist dir. And you will have to create an empty 'kiwi' directory in the dist/pixmaps directory that you just copied there. (note: I have not tested kiwi with the Innosetup installer, but if you try it and it works edit this page and remove this note :) )

Note you'll want to set the working directory (Start in:) for any shortcut you create to the application directory containing the executable.

(Optional) an Innosetup .iss file to create an installer for handytool:

[Setup]
AppName=handytool
AppVerName=handytool 1.0
AppPublisher=me
AppPublisherURL=http://www.localhost.me
DefaultDirName={pf}\handytool
DefaultGroupName=handytool
DisableProgramGroupPage=true
OutputBaseFilename=setup
Compression=lzma
SolidCompression=true
AllowUNCPath=false
VersionInfoVersion=1.0
VersionInfoCompany=me inc
VersionInfoDescription=handytool
PrivilegeRequired=admin

[Dirs]
Name: {app}; Flags: uninsalwaysuninstall;

[Files]
Source: dist\*; DestDir: {app}; Flags: ignoreversion recursesubdirs createallsubdirs

[Icons]
Name: {group}\handytool; Filename: {app}\handytool.exe; WorkingDir: {app}

[Run]
; If you are using GTK's built-in SVG support, uncomment the following line.
;Filename: {cmd}; WorkingDir: "{app}"; Parameters: "/C gdk-pixbuf-query-loaders.exe > lib/gdk-pixbuf-2.0/2.10.0/loaders.cache"; Description: "GDK Pixbuf Loader Cache Update"; Flags: nowait runhidden
Filename: {app}\handytool.exe; Description: {cm:LaunchProgram,handytool}; Flags: nowait postinstall skipifsilent

This Recipe has been tested with:

Py2exeAndPyGTK (last edited 2012-10-05 04:21:07 by 24-217-160-200)