Python scipy module import error due to missing ._

2020-02-12 10:21发布

问题:

I have some troubles with sub-module integrate from scipy in python. I have a 64 bits architecture, and it seems, according to the first lines of the python interpreter (see below) that I am also using a 64 bit build of Python together with Anaconda.

Below is the problem (I just wrote the minimal code to show what's happening)


Python 3.4.3 |Anaconda 2.3.0 (64-bit)| (default, Mar  6 2015, 12:06:10) [MSC v.1600 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import scipy
>>> import scipy.integrate
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\*********\Anaconda3\lib\site-packages\scipy\integrate\__init__.py", line 55, in <module>
    from .quadrature import *
  File "C:\Users\*********\Anaconda3\lib\site-packages\scipy\integrate\quadrature.py", line 10, in <module>
    from scipy.special.orthogonal import p_roots
  File "C:\Users\*********\Anaconda3\lib\site-packages\scipy\special\__init__.py", line 636, in <module>
    from ._ufuncs import *
ImportError: DLL load failed: Le module spécifié est introuvable.

The same happens with import scipy.special

As you can see scipy can be imported, however scipy.integrate generates an error. What is odd is that in the folder ...\lib\site-packages\scipy\special, the ._ufuncs.pyd is appears. Also, I am using scipty regularly for other purposes, and everythings works usually fine.

I am using version 0.18.0 of scipy and pip 1.8.1. I tried to reinstall scipy with conda but this does not seem to change anything.

It seems that the dll cannot be found. I found a few posts on the internet (including one that advises to download a "libmmd.dll" in C:\Windows\SysWOW64) with similar issue, but none seems to work. My guess is that this is still a pb of 32-64 bit compatibility as this is the most common pb with python and I remembered having huge pb when first seting up everything a few months ago.

So, following up the initial question, is there a way to know which version (32 bit or 64 bit) of each package or dll is effectively installed/loaded? Do you have another idea why I get this error message?

Thank you for your answers, this problem is quite frustrating...

回答1:

If you use conda and don't want to install MKL and copy the DLLs as mentioned above, I figured out you can fix this by reinstalling icc_rt package:

conda remove icc_rt --force
conda install icc_rt --no-deps

The icc_rt package has the required DLLs (LIBIFCOREMD.DLL and LIBMMD.DLL).

Below is how I investigated this issue:

I encountered the issue after upgrading my Anaconda to latest version using:

conda update conda
conda update anaconda

I ran Process Monitor while doing import scipy.special to trace which DLL it's trying to load and found out it's libifcoremd.dll.

I then searched my conda pkg cache folder (~/AppData/Local/Continuum/Anaconda3) to find out which package carries this DLL

$ find . -name '*ifcoremd.*'
./pkgs/icc_rt-2017.0.4-h97af966_0/Library/bin/libifcoremd.dll
./pkgs/mkl-11.3.3-1/Library/bin/libifcoremd.dll
./pkgs/mkl-2017.0.1-0/Library/bin/libifcoremd.dll
./pkgs/mkl-2017.0.3-0/Library/bin/libifcoremd.dll

So it's in both mkl and icc_rt packages. But it looks like the latest anaconda (5.2.0) shipped a more recent version of mkl which apparently doesn't have the DLLs anymore:

$ conda list|egrep '^(mkl|icc_rt)\s'
icc_rt                    2017.0.4             h97af966_0
mkl                       2018.0.2                      1

So presumably when conda upgraded my mkl, it deleted the DLLs from my Library\bin folder. So by force reinstalling icc_rt, I got the DLLs back.



回答2:

I solved by the following steps:

  1. Install MKL.

  2. And for my situation, I checked \scipy\special\_ufuncs.cp36-win_amd64.pyd using Dependency Wakler. Found I miss LIBIFCOREMD.DLL and LIBMMD.DLL. I solved this by install Intel Distribution for Python. Intel Distribution for Python is actually a special version of Python 3.5. And it includes lots of DLL needed. After installing Intel Distribution for Python, go to path_to_Intel_Distribution_for_Python\Library\bin(on my computer is C:\IntelPython3\Library\bin), and copy all folder and files to path_to_your_default_python\Library\bin(on my computer is C:\Anaconda3\Library\bin). (ignore other missing dlls according to this answer).

Then problem solved.

PS. Maybe sometimes files in path_to_Intel_Distribution_for_Python\Library\include\ are also needed?

PPS. You can uninstall Intel Distribution for Python if you no longer need it.

PPPS. A more simple way is to use the wheel. Unofficial Windows Binaries for Python Extension Packages. but I like to use conda update --all to update packages... then everything messed up...



回答3:

It appears the DLL load failed because the module specified is irretrievable?

Please see:

ImportError: DLL load failed: %1 is not a valid Win32 application. But the DLL's are there