0

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?

sophros
  • 14,672
  • 11
  • 46
  • 75
Manj
  • 63
  • 6
  • Does this answer your question? [Can't install new packages for Python (Python 3.9.0, Windows 10)](https://stackoverflow.com/questions/64323080/cant-install-new-packages-for-python-python-3-9-0-windows-10) – sophros Dec 15 '20 at 15:55

1 Answers1

0

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?

Twenkid
  • 825
  • 7
  • 15
  • How do I know if I have them installed – Manj Dec 15 '20 at 16:28
  • Search for the files. – Twenkid Dec 15 '20 at 18:30
  • I don't have them installed – Manj Dec 16 '20 at 12:12
  • Where did you search? On my machine I found them in: C:\Program Files\Python38\Lib\site-packages\numpy\DLLs\ So if they're missing it may be something about the numpy installation or incompatible versions which may require to remove some of the conflicting library and install it again with a more specific version. – Twenkid Dec 16 '20 at 19:05
  • I searched in the python 39 folder. There's a numpy folder but there's no DLL folder in the numpy folder. How do I figure out which library is conflicting? – Manj Dec 16 '20 at 23:54
  • So maybe you don't have numpy, can you do: "import numpy" in python console? As mentioned (see the error messages you've posted), it seems it is in Ctypes and Numpy, Ctypes complains that libs are missing or so. I'd try: python -m pip uninstall numpy python -m pip uninstall scipy Then install again, possibly from wheels which are for your version of python, "39": https://www.lfd.uci.edu/~gohlke/pythonlibs/ //In the folder where they are downloaded: python -m pip install numpy‑1.19.4+vanilla‑cp39‑cp39‑win_amd64.whl python -m pip install scipy‑1.5.4‑cp39‑cp39‑win_amd64.whl – Twenkid Dec 17 '20 at 00:43