Pushing Python to Windows workstations
Peter Hansen
peter at engcorp.com
Mon May 5 18:45:57 EDT 2003
C42 wrote:
>
> If you wouldn't mind posting the script that would be great. I've been
> trying to get this to work all afternoon and so far haven't had much luck.
Okay, here goes. For simplicity, I assume you have the following files in a
directory that is in sys.path. You can use PYTHONPATH, or .pth files as noted
in site.py or some other approach. The files are:
sitecustomize.py (loads automatically from site.py)
pythoncom.py (loaded if you import pythoncom)
pywintypes.py (loaded if you import pywintypes)
dll_import.py (utility routines used by above two)
sitecustomize.py contains:
-------------------------
# site customization file for network installation of Python,
# to workaround problem loading win32api before either
# of these is loaded.
import pythoncom
import pywintypes
-------------------------
pythoncom.py contains:
-------------------------
# fake some stuff out so anyone can import pythoncom from a network install
import dll_import
dll_import.dll_import('pythoncom')
-------------------------
pywintypes.py contains:
-------------------------
# fake some stuff out so anyone can import pywintypes from a network install
import dll_import
dll_import.dll_import('pywintypes')
-------------------------
dll_import.py contains:
-------------------------
# fake some stuff out so importing win32 works with a network install
import imp, sys, os
# patch pre-2.2 Pythons
if not hasattr(sys, '_getframe'):
def _getframe():
try:
1/0
except:
f = sys.exc_info()[2].tb_frame.f_back
return f
sys._getframe = _getframe
def dll_import(modulename):
# find my caller
f = sys._getframe().f_back
# build name of DLL with version number
ver = '%1d%1d' % sys.version_info[:2]
filename = modulename + ver + '.dll'
dllpath = os.path.join(sys.exec_prefix, filename)
# Python can load the module
mod = imp.load_module(modulename, None, dllpath, ('.dll', 'rb',
imp.C_EXTENSION))
# inject it into the global module list.
sys.modules[modulename] = mod
# And finally inject it into the globals() of my caller
f.f_globals[modulename] = mod
-------------------------
Let me know if that (a) works, (b) is clear enough to use as-is. If
not the former, I'll try to help troubleshoot. If not the latter,
I *might* be able to help explain, but as I said this was developed
by trial-and-error. Perhaps Mark Hudson or someone else can explain
why this appears to be necessary.
-Peter
More information about the Python-list
mailing list