Skip to content

Commit ac8116d

Browse files
committed
Try init_dll_path like in audio. But they only do it on 3.8
1 parent e4f00a4 commit ac8116d

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/torchcodec/_core/ops.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,29 @@
1313
from typing import List, Optional, Tuple, Union
1414

1515
import torch
16+
17+
18+
def _init_dll_path():
19+
"""Initialize DLL search paths for Windows
20+
21+
On Windows Python-3.8+ has `os.add_dll_directory` call,
22+
which is called to configure dll search path.
23+
To find FFmpeg and other dependent dlls we need to make sure the
24+
conda environment/bin path and other system paths are configured.
25+
"""
26+
if os.name == "nt":
27+
for path in os.environ.get("PATH", "").split(";"):
28+
if os.path.exists(path):
29+
try:
30+
os.add_dll_directory(path)
31+
except Exception:
32+
# Ignore paths that can't be added
33+
pass
34+
35+
36+
# Initialize DLL paths on Windows before attempting to load libraries
37+
if os.name == "nt":
38+
_init_dll_path()
1639
from torch.library import get_ctx, register_fake
1740

1841
from torchcodec._internally_replaced_utils import ( # @manual=//pytorch/torchcodec/src:internally_replaced_utils

0 commit comments

Comments
 (0)