Win32, COM and the Installer
Greg Landrum
glandrum at my-deja.com
Wed Sep 20 11:29:31 EDT 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',
imp.C_EXTENSION))
# inject it into the global module list.
sys.modules[modulename] = mod
# And finally inject it into the namespace.
globals()[modulename] = mod
win32api.FreeLibrary(h)
try:
import pywintypes
except ImportError:
magic_import("pywintypes", "pywintypes15.dll")
try:
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 (Simple.py) against this, I get the familiar
error:
IOError: [Errno 2] No such file or directory: 'c:\\windows\\system32
\\pywintypes.dll'
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
frustration.
Thanks,
-greg
Sent via Deja.com http://www.deja.com/
Before you buy.
More information about the Python-list
mailing list