28

Initially I was getting this error (No Module name was found scipy) So I installed a Scipy wheel file. Now I don't get the same error any more but I get cannot import name "_ccallback_c".

The error seems to be triggered at the fourth line of code. I have done my research and saw that other people suggested to try an environment such as Anaconda. I have seen it work on idle, and that solution isn't ideal for me.

Traceback:

Traceback (most recent call last):
  File "C:\Users\joesh\Desktop\Python\Machine Learning\1st tutorial.py", line 4, in <module>
    from sklearn import preprocessing, cross_validation, svm
  File "C:\Users\joesh\Desktop\Python\lib\site-packages\sklearn\__init__.py", line 134, in <module>
    from .base import clone
  File "C:\Users\joesh\Desktop\Python\lib\site-packages\sklearn\base.py", line 10, in <module>
    from scipy import sparse
  File "C:\Users\joesh\Desktop\Python\lib\site-packages\scipy\__init__.py", line 118, in <module>
    from scipy._lib._ccallback import LowLevelCallable
  File "C:\Users\joesh\Desktop\Python\lib\site-packages\scipy\_lib\_ccallback.py", line 1, in <module>
    from . import _ccallback_c
ImportError: cannot import name '_ccallback_c'

And the code:

import pandas as pd
import quandl, math
import numpy as np
from sklearn import preprocessing, cross_validation, svm 
from sklearn.linear_model import LinearRegression
SiHa
  • 7,830
  • 13
  • 34
  • 43
Joeski
  • 283
  • 1
  • 3
  • 9
  • 1
    Try installing your requirements from http://www.lfd.uci.edu/~gohlke/pythonlibs using wheels. I hope it would work. – Harman Oct 13 '17 at 02:51
  • @Harman I just did. No luck – Joeski Oct 13 '17 at 03:36
  • 1
    what is the version of SciPy? Please add the output of one of the following commands to the question `python3 -c 'import scipy; print(scipy.__version__)'` or `python -c 'import scipy; print scipy.__version__'` – Pierre de Buyl Oct 13 '17 at 14:22
  • 2
    Did you ever figure this out? Im curious to know the solution having the same problem – Tyler Cowan Jan 02 '18 at 23:31
  • 2
    This looks like a version mismatch of Python and scipy. Make sure your scipy dependency is the correct one for your version of Python. – asmaier May 14 '19 at 16:16

8 Answers8

21

I had the same error on USING Anaconda, so I am not sure if using it would make any difference. I solved it by just uninstalling scipy and re-installing it using pip:

pip uninstall scipy 

you'll get this message:

Uninstalling scipy-1.1.0: Would remove: c:\users\thesh\appdata\local\programs\python\python36-32\lib\site-packages\scipy-1.1.0.dist-info* c:\users\thesh\appdata\local\programs\python\python36-32\lib\site-packages\scipy* Proceed (y/n)?

press y, and after pip is done, type:

pip install scipy
barshopen
  • 1,190
  • 2
  • 15
  • 28
  • This is very helpful but also infuriating. I just started using miniconda, and that is when this error started happening for me. I thought conda was supposed to make package management easier, not harder... +1 to you for helping me out though. – Owen Mar 21 '19 at 13:43
4

Having just moved to MSVS 2017 for Python (ML) development, I encountered this and other errors related to missing modules. The problem (and all related problems like it) has a frustratingly simple solution: when I originally started coding in Python, I installed everything from the command line - apparently, MSVS 2017 doesn't "see" those installations (and, in fact, they sometimes conflict, since the underlying python may be tapping older libs); so, the solution is to:

Use the command line version of 'pip uninstall ...' where '...' is the library having missing dependencies (scipy, in this case). Then, in the MSVS 2017 command line on the Python environment window (usually, top right in the default display configuration), reload the library (in this case, typing 'scipy' will format a command line for execution [in the list control below the command textbox]) that will read something like 'pip install scipy' (or whatever library needs to be reinstalled for MSVS).

You may have to do this for many (or all) of your previous Python package installations where these missing module errors persist.

4

Can be resolved, by uninstalling and reinstalling using pip on Anaconda Prompt:

pip uninstall scipy

After the uninstall, you can reinstall with:

pip install scipy
Zoe
  • 27,060
  • 21
  • 118
  • 148
Grace U. Nneji
  • 331
  • 5
  • 8
2

When you installed scipy with pip in a Python version 3.6 and later try to run your code with Python 3.7 you will encounter this problem. So one solution is to uninstall scipy

pip3 uninstall scipy

and reinstall it (using an environment with Python 3.7):

pip3 install scipy 

This will make sure that the installed version of scipy is compatible with your version of Python.

PS: When you updated Python from Python 3.6 to Python 3.7 it might be necessary to also reinstall pip, so that pip will use the correct version of Python internally.

asmaier
  • 11,132
  • 11
  • 76
  • 103
2

I ran into this when I was following these instructions on how to use a virtual environment to use the pre-built version of SciPy. The simplest solution for me was to simply comment out from . import _ccallback_c under scipy\_lib\_ccallback.py.

Yuna Luzi
  • 318
  • 2
  • 9
  • didn't help for me, because I got a new error afterwards: `Python Exception : cannot import name '_fblas' from partially initialized module 'scipy.linalg' (most likely due to a circular import` – saQuist Apr 07 '23 at 14:45
0

I first had the error with scipy. So I ran the command python -m pip install -user numpy scipy matplotlib ipython jupyter pandas sympy noseand it worked perfectly. I was installing everything with pip, so I decided to use Anaconda. I installed and checked to add to the PATH. From there, the same code that was executed before normally stopped working and displays the error similar to that of the question. I uninstalled Anaconda and it is now working again.

Erro:

$ winpty python ia.py
Traceback (most recent call last):
  File "ia.py", line 11, in <module>
    from sklearn import tree #importando a biblioteca e a árvore p/ o classifica
dor
  File "C:\Users\ferna\Anaconda3\lib\site-packages\sklearn\__init__.py", line 13
4, in <module>
    from .base import clone
  File "C:\Users\ferna\Anaconda3\lib\site-packages\sklearn\base.py", line 11, in
 <module>
    from scipy import sparse
  File "C:\Users\ferna\AppData\Roaming\Python\Python36\site-packages\scipy\__ini
t__.py", line 118, in <module>
    from scipy._lib._ccallback import LowLevelCallable
  File "C:\Users\ferna\AppData\Roaming\Python\Python36\site-packages\scipy\_lib\
_ccallback.py", line 1, in <module>
    from . import _ccallback_c
ImportError: cannot import name '_ccallback_c'

Código:

from sklearn import tree #importando a biblioteca e a árvore p/ o classificador
#COLLLECT TRAINING DATA
features = [[140,1],[130,1],[150,0],[170,0]]
labels = [0,0,1,1]
# TRAIN CLASSIFIER 
clf = tree.DecisionTreeClassifier() #Classificador
clf = clf.fit(features, labels) #algoritmo de decisão p/ encontrar padrões
#MAKE PREDICTIONS
print(clf.predict([[160, 0]])) #entrada de dados para o tratamento
0

Try this:

python -m pip install --upgrade scipy
Paul Roub
  • 36,322
  • 27
  • 84
  • 93
Omar Merghany
  • 155
  • 1
  • 2
  • 9
0

After digging in, to give the full background on this, first of all SciPy relies on having NumPy already installed. The SciPy wheel's setup.py file uses NumPy functionality to configure and install the wheel.

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

from . import _ccallback_c

These file names seem to be an artifact of libraries that are using Cython and Cython's adherence to PEP 3149 (ABI version tagged .so files). 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. Then change .zip -> .whl and it should be good to go unless it's the wrong architecture for the platform you're using, in which case you need to download the appropriate platform wheel for your platform.

Alex W
  • 37,233
  • 13
  • 109
  • 109