Skip to content

Commit

Permalink
Change how the directory with the pywin32 DLLs is treated at startup.
Browse files Browse the repository at this point in the history
This directory is now added to the start of PATH for version 3.7 and earlier,
and passed to os.add_dll_directory() on 3.8 and later. This will hopefully
work around problems loading pywintypes.dll in various situations.

Fixes #1432, fixes #1431
  • Loading branch information
mhammond committed Nov 5, 2019
1 parent 30fd67c commit 71afa71
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
5 changes: 5 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ However contributors are encouraged to add their own entries for their work.

Since build 225:
----------------
* The directory with the pywin32 system DLLs is now added to the start of PATH
for version 3.7 and earlier, and passed to os.add_dll_directory() on 3.8 and
later. This will hopefully work around problems loading pywintypes.dll in
various situations.

* Conversions to and from COM VT_DATE types should no longer lose milliseconds.

Since build 224:
Expand Down
8 changes: 3 additions & 5 deletions pywin32.pth
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
win32
win32\lib
Pythonwin
# Entries needed for a "portable" installations, where the post_install script
# isn't run, which would normally copy the pywin32 core DLL files to either
# the top of the python directory.
# We just stick the source of these DLLs directly on the PATH.
import os;pywin32_system32=os.path.join(sitedir,"pywin32_system32");os.environ["PATH"]+=('' if pywin32_system32 in os.environ["PATH"] else (';'+pywin32_system32))
# And some hackery to deal with environments where the post_install script
# isn't run.
import pywin32_bootstrap
21 changes: 21 additions & 0 deletions win32/Lib/pywin32_bootstrap.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Imported by pywin32.pth to bootstrap the pywin32 environment in "portable"
# environments or any other case where the post-install script isn't run.
#
# In short, there's a directory installed by pywin32 named 'pywin32_system32'
# with some important DLLs which need to be found by Python when some pywin32
# modules are imported.
# If Python has `os.add_dll_directory()`, we need to call it with this path.
# Otherwise, we add this path to PATH.
import os
import site
import sys

# The directory should be installed under site-packages.
for maybe in site.getsitepackages():
pywin32_system32=os.path.join(maybe,"pywin32_system32")
if os.path.isdir(pywin32_system32):
if hasattr(os, "add_dll_directory"):
os.add_dll_directory(pywin32_system32)
else:
os.environ["PATH"] = pywin32_system32 + ";" + os.environ["PATH"]

0 comments on commit 71afa71

Please sign in to comment.