Win32, COM and the Installer

Greg Landrum glandrum at
Wed Sep 20 17:29:31 CEST 2000

[I realize that this is somewhat of a FAQ, but I have not been able
to make the previously posted solutions work at all.  I would like
to get a single answer posted that other people could track down.]

I'd like to construct a standalone windows program using Gordon
McMillan's installer which uses the wonderful win32com stuff.  I'm
running Win2K, Python 1.5.2, PythonWin build 132 and Installer 0.3f.

Here's a very simple script I want to build an installer for, note
that it imports win32com, but does not actually use it (to simplify
the script):

import win32api
import sys,imp
# pythoncom and pywintypes are special, and require these hacks when
# built into a .EXE
def magic_import(modulename, filename):
  # win32 can find the DLL name.
  h = win32api.LoadLibrary(filename)
  found = win32api.GetModuleFileName(h)
  # Python can load the module
  mod = imp.load_module(modulename, None, found, ('.dll', 'rb',
  # inject it into the global module list.
  sys.modules[modulename] = mod
  # And finally inject it into the namespace.
  globals()[modulename] = mod

  import pywintypes
except ImportError:
  magic_import("pywintypes", "pywintypes15.dll")
  import pythoncom
except ImportError:
  magic_import("pythoncom", "pythoncom15.dll")

from win32com.client import gencache

print 'hello world'

The magic_import() bits here are from an earlier post by Mark Hammond.

When I run the installer ( against this, I get the familiar

IOError: [Errno 2] No such file or directory: 'c:\\windows\\system32

If someone can provide me with a .cfg file which works to create an
installer/standalone for this script, I will be eternally grateful
and will put together a HowTo in an effort to help fend off future


Sent via
Before you buy.

More information about the Python-list mailing list