Skip to content

Commit 71afa71

Browse files
committed
Change how the directory with the pywin32 DLLs is treated at startup.
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
1 parent 30fd67c commit 71afa71

File tree

3 files changed

+29
-5
lines changed

3 files changed

+29
-5
lines changed

CHANGES.txt

+5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ However contributors are encouraged to add their own entries for their work.
66

77
Since build 225:
88
----------------
9+
* The directory with the pywin32 system DLLs is now added to the start of PATH
10+
for version 3.7 and earlier, and passed to os.add_dll_directory() on 3.8 and
11+
later. This will hopefully work around problems loading pywintypes.dll in
12+
various situations.
13+
914
* Conversions to and from COM VT_DATE types should no longer lose milliseconds.
1015

1116
Since build 224:

pywin32.pth

+3-5
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
win32
33
win32\lib
44
Pythonwin
5-
# Entries needed for a "portable" installations, where the post_install script
6-
# isn't run, which would normally copy the pywin32 core DLL files to either
7-
# the top of the python directory.
8-
# We just stick the source of these DLLs directly on the PATH.
9-
import os;pywin32_system32=os.path.join(sitedir,"pywin32_system32");os.environ["PATH"]+=('' if pywin32_system32 in os.environ["PATH"] else (';'+pywin32_system32))
5+
# And some hackery to deal with environments where the post_install script
6+
# isn't run.
7+
import pywin32_bootstrap

win32/Lib/pywin32_bootstrap.py

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Imported by pywin32.pth to bootstrap the pywin32 environment in "portable"
2+
# environments or any other case where the post-install script isn't run.
3+
#
4+
# In short, there's a directory installed by pywin32 named 'pywin32_system32'
5+
# with some important DLLs which need to be found by Python when some pywin32
6+
# modules are imported.
7+
# If Python has `os.add_dll_directory()`, we need to call it with this path.
8+
# Otherwise, we add this path to PATH.
9+
import os
10+
import site
11+
import sys
12+
13+
# The directory should be installed under site-packages.
14+
for maybe in site.getsitepackages():
15+
pywin32_system32=os.path.join(maybe,"pywin32_system32")
16+
if os.path.isdir(pywin32_system32):
17+
if hasattr(os, "add_dll_directory"):
18+
os.add_dll_directory(pywin32_system32)
19+
else:
20+
os.environ["PATH"] = pywin32_system32 + ";" + os.environ["PATH"]
21+

0 commit comments

Comments
 (0)