ImportError: cannot import name _distributor_init

2020-07-22 10:11发布

问题:

While trying to import scipy, I'm getting the following error :

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-7-4dc45f4c0083> in <module>()
----> 1 import scipy

C:\Users\admin\Anaconda2\lib\site-packages\scipy\__init__.py in <module>()
     74 
     75 # Allow distributors to run custom init code
---> 76 from . import _distributor_init
     77 
     78 __all__ += _num.__all__

ImportError: cannot import name _distributor_init

I have tried re-installing from pip by force reinstall, it says that scipy is up-to-date but then, loading it gives the above error. How do I resolve it? I'm using Python 2.x version.

回答1:

I was getting the same error while using cx_freeze, i managed to make it work by simply commenting this line in the init.py of scipy (---> 76 from . import _distributor_init). From what i read there: [Numpy-discussion] Hook in init.py to let distributors patch numpy it simply enables more customization of checks, that i didn't need. Scipy seems to work just fine without it. Fyi I installed scipy without using anaconda, and i use python 3.6. Hope this helps.



回答2:

I use cx_Freeze and package have this error. I add this code to solve this problem:

self.build_exe_options = {
    'includes': "scipy._distributor_init"
}


标签: python scipy pip