Skip to content

Commit ff11071

Browse files
committed
Add common BLAS paths
1 parent 82d176a commit ff11071

File tree

1 file changed

+26
-9
lines changed

1 file changed

+26
-9
lines changed

pfapack/ctypes.py

+26-9
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,32 @@ def _find_library() -> ctypes.CDLL:
2929

3030
# On Windows, ensure OpenBLAS and its dependencies can be found
3131
if os.name == "nt":
32-
# Add MSYS2 bin directory to DLL search path
33-
msys2_bin = Path("C:/msys64/mingw64/bin")
34-
if msys2_bin.exists():
35-
os.add_dll_directory(str(msys2_bin)) # type: ignore[attr-defined]
36-
try:
37-
# Load OpenBLAS directly from MSYS2
38-
ctypes.CDLL(str(msys2_bin / "libopenblas.dll"))
39-
except OSError as e:
40-
print(f"Warning: Failed to load OpenBLAS: {e}")
32+
# Common locations for OpenBLAS on Windows
33+
possible_blas_paths = [
34+
Path("C:/msys64/mingw64/bin"), # MSYS2 MinGW64
35+
Path("C:/msys64/ucrt64/bin"), # MSYS2 UCRT64
36+
Path("C:/msys64/clang64/bin"), # MSYS2 Clang64
37+
Path(os.environ.get("OPENBLAS_PATH", "")).parent
38+
/ "bin", # Custom installation
39+
Path(os.environ.get("CONDA_PREFIX", "")) / "Library" / "bin", # Conda
40+
]
41+
42+
# Try to find and load OpenBLAS from any of these locations
43+
blas_loaded = False
44+
for path in possible_blas_paths:
45+
if path.exists():
46+
try:
47+
os.add_dll_directory(str(path)) # type: ignore[attr-defined]
48+
openblas_path = path / "libopenblas.dll"
49+
if openblas_path.exists():
50+
ctypes.CDLL(str(openblas_path))
51+
blas_loaded = True
52+
break
53+
except OSError as e:
54+
print(f"Warning: Failed to load OpenBLAS from {path}: {e}")
55+
56+
if not blas_loaded:
57+
print("Warning: Could not load OpenBLAS from any known location")
4158

4259
# Try all possible library names
4360
lib_names = [

0 commit comments

Comments
 (0)