Skip to content

Commit cc83997

Browse files
authored
feat: Disable loading Python DLLs from PATH by default on Windows (#4590)
Users can enable the legacy behavior by setting env var `OIIO_PYTHON_LOAD_DLLS_FROM_PATH=1`. This commit also changes the environment variable name from `OIIO_LOAD_DLLS_FROM_PATH` to `OIIO_PYTHON_LOAD_DLLS_FROM_PATH` to match the convention used by OCIO. This PR addresses issue #4519 --------- Signed-off-by: Zach Lewis <[email protected]>
1 parent dc409d8 commit cc83997

File tree

4 files changed

+27
-2
lines changed

4 files changed

+27
-2
lines changed

Diff for: .github/workflows/ci.yml

+2
Original file line numberDiff line numberDiff line change
@@ -589,8 +589,10 @@ jobs:
589589
vsver: 2019
590590
generator: "Visual Studio 16 2019"
591591
python_ver: "3.9"
592+
setenvs: export OPENIMAGEIO_PYTHON_LOAD_DLLS_FROM_PATH=1
592593
- desc: Windows-2022 VS2022
593594
runner: windows-2022
594595
vsver: 2022
595596
generator: "Visual Studio 17 2022"
596597
python_ver: "3.9"
598+
setenvs: export OPENIMAGEIO_PYTHON_LOAD_DLLS_FROM_PATH=1

Diff for: INSTALL.md

+9
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,15 @@ produce a dynamic-linked version.
357357

358358
3. Execute the PowerShell command from where vcpkg is located in directory. ``vcpkg install openimageio``
359359

360+
361+
**Note: Importing the OpenImageIO Python Module**
362+
363+
As of OpenImageIO 3.0.3.0, the default DLL-loading behavior for Python 3.8+ has changed.
364+
365+
If you've built OIIO from source and ``import OpenImageIO`` is throwing a ModuleNotFound exception, revert to the legacy DLL-loading behavior by setting environment variable
366+
``OPENIMAGEIO_PYTHON_LOAD_DLLS_FROM_PATH=1``.
367+
368+
360369
Test Images
361370
-----------
362371

Diff for: src/doc/imageioapi.rst

+14
Original file line numberDiff line numberDiff line change
@@ -384,3 +384,17 @@ inside the source code.
384384
name and version of the software and an indecipherable hash of the command
385385
line, but not the full human-readable command line. (This was added in
386386
OpenImageIO 2.5.11.)
387+
388+
.. cpp:var:: OPENIMAGEIO_PYTHON_LOAD_DLLS_FROM_PATH
389+
390+
Windows only. Mimics the DLL-loading behavior of Python 3.7 and earlier.
391+
If set to "1", all directories under ``PATH`` will be added to the DLL load
392+
path before attempting to import the OpenImageIO module. (This was added in
393+
OpenImageIO 3.0.3.0)
394+
395+
Note: This "opt-in-style" behavior replaces and inverts the "opt-out-style"
396+
Windows DLL-loading behavior governed by the now-defunct `OIIO_LOAD_DLLS_FROM_PATH`
397+
environment variable (added in OpenImageIO 2.4.0/2.3.18).
398+
399+
In other words, to reproduce the default Python-module-loading behavior of
400+
earlier versions of OIIO, set ``OPENIMAGEIO_PYTHON_LOAD_DLLS_FROM_PATH=1``.

Diff for: src/python/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
# This works around the python 3.8 change to stop loading DLLs from PATH on Windows.
88
# We reproduce the old behaviour by manually tokenizing PATH, checking that the directories exist and are not ".",
99
# then add them to the DLL load path.
10-
# This behviour can be disabled by setting the environment variable "OIIO_LOAD_DLLS_FROM_PATH" to "0"
11-
if sys.version_info >= (3, 8) and platform.system() == "Windows" and os.getenv("OIIO_LOAD_DLLS_FROM_PATH", "1") == "1":
10+
# This behviour can be enabled by setting the environment variable "OPENIMAGEIO_PYTHON_LOAD_DLLS_FROM_PATH" to "1"
11+
if sys.version_info >= (3, 8) and platform.system() == "Windows" and os.getenv("OPENIMAGEIO_PYTHON_LOAD_DLLS_FROM_PATH", "0") == "1":
1212
for path in os.getenv("PATH", "").split(os.pathsep):
1313
if os.path.exists(path) and path != ".":
1414
os.add_dll_directory(path)

0 commit comments

Comments
 (0)