scipy: DLL load error while importing scipy.sparse.linalg module on Windows

My bug report is about DLL load error on running scipy-1.3.2 library for Windows 10 64bit

Reproducing code example:

import scipy.sparse.linalg
print("loaded")

After small research I’ve identified a culput, there is no PATH env setup for windows platform inside __config__.py of scipy package, or it’s not get executed correctly.

if sys.platform == 'win32' and os.path.isdir(extra_dll_dir):
    os.environ.setdefault('PATH', '')
    os.environ['PATH'] += os.pathsep + extra_dll_dir

Henceforth, the path to .libs folder is not added to Windows path and libraries never ever gets found.

Error message:

Traceback (most recent call last):
  File "test_lib.py", line 1, in <module>
    import scipy.sparse.linalg
  File "C:\apps\Python37\lib\site-packages\scipy\sparse\linalg\__init__.py", line 113, in <module>
    from .isolve import *
  File "C:\apps\Python37\lib\site-packages\scipy\sparse\linalg\isolve\__init__.py", line 6, in <module>
    from .iterative import *
  File "C:\apps\Python37\lib\site-packages\scipy\sparse\linalg\isolve\iterative.py", line 10, in <module>
    from . import _iterative
ImportError: DLL load failed

Scipy/Numpy/Python version information:

Python 3.7.5 win64 scipy-1.3.2 numpy-1.17.4

Temporary workaround I’m using for the moment being, is a small update within __init__.py repeating the missing search path addition.

import os
import sys

extra_dll_dir = os.path.join(os.path.dirname(__file__), '.libs')
if sys.platform == 'win32' and os.path.isdir(extra_dll_dir):  
  os.environ['PATH'] = extra_dll_dir + os.pathsep + os.environ['PATH']

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 3
  • Comments: 49 (44 by maintainers)

Most upvoted comments

Thanks for finding that.