[python-win32] Running Python + pywin32 portably

Dietmar Schwertberger maillist at schwertberger.de
Sun Feb 5 14:37:06 CET 2012


Am 04.02.2012 02:38, schrieb Mark Hammond:
> Not running the postinstall script just means that pywintypesxx.dll and
> pythoncomxx.dll aren't in system32. Assuming you have control over the
> environment this is running in, just ensuring those files are on the
> PATH should be sufficient.

Yes, I have been running portable Python installations for years.
In the sitecustomize.py I'm just adding the required directories to the
path:


import sys, os

# add DLL directories to path environment variable
path = original_path = os.environ["path"]

splitted = path.split(";")
splitted_l = path.lower().split(";")
dlls = os.path.join(sys.exec_prefix, "DLLs")
pythonwin = os.path.join(sys.exec_prefix, r"Lib\site-packages\pythonwin")
pythonwin_system32 = os.path.join(sys.exec_prefix, 
r"Lib\site-packages\pywin32_system32")

dlldirs = [sys.exec_prefix, dlls, pythonwin, pythonwin_system32]

for dlldir in dlldirs:
     if dlldir.lower() in splitted_l: continue
     path = path+";"+dlldir


if path!=original_path:
     os.environ["path"] = path

del dlls, dlldir, dlldirs, pythonwin, pythonwin_system32



Regards,

Dietmar



More information about the python-win32 mailing list