【问题标题】:ImportError: cannot import name _distributor_initImportError:无法导入名称 _distributor_init
【发布时间】:2018-01-24 13:34:37
【问题描述】:

在尝试导入 scipy 时,我收到以下错误:

---------------------------------------------------------------------------
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

我尝试通过强制重新安装从 pip 重新安装,它说 scipy 是最新的,但是加载它会出现上述错误。我该如何解决?我正在使用 Python 2.x 版本。

【问题讨论】:

    标签: python scipy pip


    【解决方案1】:

    我在使用 cx_freeze 时遇到了同样的错误,我通过简单地在 scipy 的 init.py 中注释这一行(---> 76 from .import _distributor_init)设法使它工作。 从我那里读到的:[Numpy-discussion] Hook in init.py to let distributors patch numpy 它只是启用了我不需要的检查的更多自定义。 没有它,Scipy 似乎工作得很好。 仅供参考,我在没有使用 anaconda 的情况下安装了 scipy,并且我使用了 python 3.6。 希望这会有所帮助。

    【讨论】:

    • 如果我尝试评论该行,我会收到以下错误:重要提示:请阅读此内容以获得有关如何解决此问题的建议!导入多数组 numpy 扩展模块失败。您很可能正在尝试导入失败的 numpy 构建。以下是如何继续: - 如果您正在使用 numpy git 存储库,请尝试 git clean -xdf(删除所有不受版本控制的文件)并重建 numpy。 - 如果您只是尝试使用已安装的 numpy 版本:您的安装已损坏 - 请重新安装 numpy。
    【解决方案2】:

    我使用cx_Freeze 并且包有这个错误。我添加这段代码来解决这个问题:

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

    【讨论】:

      【解决方案3】:

      只要升级你的 sklearn,升级一切,你会没事的

      【讨论】:

      • 如果您认为对 OP 有帮助,能否提供一些用于升级的命令行 sn-p?
      猜你喜欢
      • 2019-07-29
      • 1970-01-01
      • 2016-03-31
      • 2014-10-10
      • 2014-09-20
      • 2014-08-28
      • 2014-06-10
      • 2016-05-16
      • 2019-05-25
      相关资源
      最近更新 更多