[python-win32] suggested change to pywintypes.py for non-admin install

Trent Mick trentm at activestate.com
Fri Mar 9 02:50:56 CET 2007


Mark and others,

For a non-admin install pywintypesXY.dll and pythoncomXY.dll cannot be put in
the system directory. The typical alternative is to put them in the install
dir, next to python.exe. "pywintypes.py" is setup to know how to find it when
doing either of:

     import pywintypes
     import pythoncom

However, doing any of (and similar):

     import win32api
     from win32com.shell import shell

fails. You have to do one of the former first.

If however we put the system DLLs next to win32api.pyd et al (and update 
pywintypes.py to look there) then those imports work. The win32comext imports 
seems to work too because "win32api" will have been imported by then.

Thoughts?

Cheers,
Trent


--- pywin32/win32/Lib/pywintypes.py.original	Tue Mar 06 09:34:49 2007
+++ pywin32/win32/Lib/pywintypes.py	Thu Mar 08 17:26:44 2007
@@ -85,9 +85,17 @@
              # This is most likely to happen for "non-admin" installs, where
              # we can't put the files anywhere else on the global path.

-            # If there is a version in our Python directory, use that
-            if os.path.isfile(os.path.join(sys.prefix, filename)):
-                found = os.path.join(sys.prefix, filename)
+            # If there is a version in our Python directory or next to
+            # win32api.pyd, use that
+            candidates = [
+                os.path.join(sys.prefix, filename),
+                os.path.join(sys.prefix, "Lib", "site-packages", "win32",
+                             filename),
+            ]
+            for candidate in candidates:
+                if os.path.isfile(candidate):
+                    found = candidate
+                    break
          if found is None:
              # give up in disgust.
              raise ImportError, \


-- 
Trent Mick
trentm at activestate.com


More information about the Python-win32 mailing list