Why can't I use scipy despite having it installed?

244 Views Asked by At

I've installed SciPy using pip on Windows Powershell. I used the command py -m pip install scipy. This worked. I then tried to import scipy into Python, but I get this error

Traceback (most recent call last):

  File "C:\Users\monzu\Documents\model of membrane-fiber interactions.py", line 2, in <module>
    import scipy
  File "C:\Users\monzu\AppData\Roaming\Python\Python39\site-packages\scipy\__init__.py", line 61, in <module>
    from numpy import show_config as show_numpy_config
  File "C:\Users\monzu\AppData\Roaming\Python\Python39\site-packages\numpy\__init__.py", line 138, in <module>
    from . import _distributor_init
  File "C:\Users\monzu\AppData\Roaming\Python\Python39\site-packages\numpy\_distributor_init.py", line 26, in <module>
    WinDLL(os.path.abspath(filename))
  File "C:\Users\monzu\AppData\Local\Programs\Python\Python39-32\lib\ctypes\__init__.py", line 374, in __init__
    self._handle = _dlopen(self._name, mode)

OSError: [WinError 193] %1 is not a valid Win32 application

How do I fix this?

1

There are 1 best solutions below

6
On

I don't know if that's the reason and how it came, but "Python39-32" and "not a valid Win32 application" may suggest a mismatch in the versions of some libraries, 32-bit vs 64-bit, or some dependency missing? Maybe a 64-bit python/numpy? is trying to import a 32-bit DLL for the cython library (the last two lines from the exception).

EDIT: I opened the __distributo_init.py file, there are these DLL loads:

   #Load Intel C, Fortran, and OMP runtime DLLs into the process
    import ctypes
    ctypes.CDLL(os.path.join(path, 'libmmd.dll'))
    ctypes.CDLL(os.path.join(path, 'libifcoremd.dll'))
    ctypes.CDLL(os.path.join(path, 'libiomp5md.dll'))

ctypes.CDLL are instances of a class where it fails.

Then:

if handle is None:
        self._handle = _dlopen(self._name, mode)
    else:
        self._handle = handle

So maybe it can't import these libraries - are they installed?