简体   繁体   English

导入 scipy 错误:无法导入名称 '_ccallback_c'

[英]import scipy error: cannot import name '_ccallback_c'

I use Anaconda3@windows to import scipy(v1.0.0) but I have an error when compiling.我使用Anaconda3@windows导入scipy(v1.0.0)但编译时出现错误。 I have checked other similar cases online but found no solution, does anyone have any idea?我在网上查了其他类似的案例,但没有找到解决办法,有谁知道吗?

import numpy as np
import scipy

The error msg错误消息

ImportError
Traceback (most recent call
last) <ipython-input-12-eb63b9337447> in <module>()
      1 import numpy as np
----> 2 import scipy

~\AppData\Roaming\Python\Python36\site-packages\scipy\__init__.py in
<module>()
    116     del _NumpyVersion
    117 
--> 118     from scipy._lib._ccallback import LowLevelCallable
    119 
    120     from scipy._lib._testutils import PytestTester

~\AppData\Roaming\Python\Python36\site-packages\scipy\_lib\_ccallback.py
in <module>()
----> 1 from . import _ccallback_c
      2 
      3 import ctypes
      4 
      5 PyCFuncPtr = ctypes.CFUNCTYPE(ctypes.c_void_p).__bases__[0]

ImportError: cannot import name '_ccallback_c'

I had the same issue and tried all recommended solutions (re-install in many different ways), but nothing worked.我遇到了同样的问题并尝试了所有推荐的解决方案(以多种不同的方式重新安装),但没有任何效果。 What helped a lot is to read documentation more carefully ( https://www.scipy.org/install.html ) In my case, scipy library also required some latest versions of other libraries to be installed, so I run: python -m pip install numpy scipy matplotlib ipython jupyter pandas sympy nose更有帮助的是更仔细地阅读文档( https://www.scipy.org/install.html )在我的情况下,scipy库还需要安装其他库的一些最新版本,所以我运行:python -m pip install numpy scipy matplotlib ipython jupyter pandas sympy鼻子

Now everything works fine.现在一切正常。

Solution found!找到解决方案!

  1. remove scipy (entire folder), in my computer where in C:\\Users(your name)\\AppData\\Roaming\\Python\\Python36\\site-packages\\scipy*删除 scipy(整个文件夹),在我的电脑中 C:\\Users(your name)\\AppData\\Roaming\\Python\\Python36\\site-packages\\scipy*
  2. download scipy from https://www.lfd.uci.edu/~gohlke/pythonlibs/#scipyhttps://www.lfd.uci.edu/~gohlke/pythonlibs/#scipy下载 scipy
  3. re-install by pip install scipy-1.0.0-cp36-cp36m-win_amd64.whl (my os is windows-64bit)通过 pip install scipy-1.0.0-cp36-cp36m-win_amd64.whl 重新安装(我的操作系统是 windows-64bit)

That's it!就是这样!

同意 Daria Simonova,如果您使用的是 Anaconda,请尝试conda update numpy scipy matplotlib ipython jupyter pandas sympy nose

After digging in, to give the full background on this, first of all SciPy relies on having NumPy already installed.在深入研究之后,为了提供完整的背景知识,首先 SciPy 依赖于已经安装了 NumPy。 The SciPy wheel's setup.py file uses NumPy functionality to configure and install the wheel. SciPy 轮的setup.py文件使用 NumPy 功能来配置和安装轮。

SciPy setup.py : SciPy setup.py

...

if __name__ == '__main__':
    from numpy.distutils.core import setup
    setup(**configuration(top_path='').todict())

Secondly, when just trying to use the wheel, if you run into this error, you can see after inspecting the wheel's files that the reason is the binary wheels have a naming convention where the shared object file, here it's called _ccallback_c.so , is instead named based on the architecture that the binary wheel supports.其次,当只是尝试使用轮子时,如果遇到此错误,您可以在检查轮子文件后看到原因是二进制轮子有一个命名约定,其中共享对象文件,这里称为_ccallback_c.so ,是而是根据二进制轮支持的架构命名。 When trying to import the shared object by file name in /_lib/_ccallback.py it can't find it, hence this error (line 1 in /_lib/_ccallback.py ) because, instead of being named _ccallback_c.so it's called _ccallback_c.cpython-36m-x86_64-linux-gnu.so or another architecture variation:当尝试通过/_lib/_ccallback.py的文件名导入共享对象时,它找不到它,因此出现此错误( /_lib/_ccallback.py第 1 /_lib/_ccallback.py ),因为它没有被命名为_ccallback_c.so所以它被称为_ccallback_c.cpython-36m-x86_64-linux-gnu.so或其他架构变体:

from . import _ccallback_c

These file names may be an artifact of having not run the NumPy setup process yet or something related to Cython, that I'm not quite sure about.这些文件名可能是尚未运行 NumPy 设置过程或与 Cython 相关的东西,我不太确定。 But the easiest fix is to change the .whl extension to .zip and rename all those relevant .so files to not contain the architecture snippet.但最简单的解决方法是将 .whl 扩展名更改为 .zip 并将所有相关的 .so 文件重命名为不包含架构片段。 Then change .zip -> .whl and it should be good to go.然后更改 .zip -> .whl 就可以了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM