问题
My sklearn works well before, after installing and updating a couple of other packages, I cannot import any model from sklearn.
The versions:
Python 2.7.12
Anaconda 2.4.1 (x86_64)
sklearn: 0.17.1 (downgrade from 0.18) spicy: 0.18.1
Measures I've tried:
restart the shell---> same error
uninstall sklearn, and reinstall it (the newest version is 0.18), downgrade it to 0.17--> same error
- install sklearn and keep the version 0.18 -->still error
My code:
from sklearn import svm
The error
Traceback (most recent call last):
File "<ipython-input-1-fe795c4388c4>", line 3, in <module>
from sklearn import svm
File "//anaconda/lib/python2.7/site-packages/sklearn/svm/__init__.py", line 13, in <module>
from .classes import SVC, NuSVC, SVR, NuSVR, OneClassSVM, LinearSVC, \
File "//anaconda/lib/python2.7/site-packages/sklearn/svm/classes.py", line 4, in <module>
from .base import _fit_liblinear, BaseSVC, BaseLibSVM
File "//anaconda/lib/python2.7/site-packages/sklearn/svm/base.py", line 11, in <module>
from ..preprocessing import LabelEncoder
File "//anaconda/lib/python2.7/site-packages/sklearn/preprocessing/__init__.py", line 8, in <module>
from .data import Binarizer
File "//anaconda/lib/python2.7/site-packages/sklearn/preprocessing/data.py", line 25, in <module>
from ..utils.sparsefuncs import (inplace_column_scale,
ImportError: cannot import name inplace_column_scale
Besides svm, when I import tree, linear_model, the same thing happens.
from sklearn.models import linear_model
The error:
Traceback (most recent call last):
File "<ipython-input-3-540f6792b379>", line 1, in <module>
from sklearn.models import linear_model
ImportError: No module named models
Code:
from sklearn import tree
error: Traceback (most recent call last):
File "<ipython-input-4-fcc6e7d2ee3e>", line 1, in <module>
from sklearn import tree
File "//anaconda/lib/python2.7/site-packages/sklearn/tree/__init__.py", line 6, in <module>
from .tree import DecisionTreeClassifier
File "//anaconda/lib/python2.7/site-packages/sklearn/tree/tree.py", line 30, in <module>
from ..feature_selection.from_model import _LearntSelectorMixin
File "//anaconda/lib/python2.7/site-packages/sklearn/feature_selection/__init__.py", line 7, in <module>
from .univariate_selection import chi2
File "//anaconda/lib/python2.7/site-packages/sklearn/feature_selection/univariate_selection.py", line 15, in <module>
from ..preprocessing import LabelBinarizer
File "//anaconda/lib/python2.7/site-packages/sklearn/preprocessing/__init__.py", line 8, in <module>
from .data import Binarizer
File "//anaconda/lib/python2.7/site-packages/sklearn/preprocessing/data.py", line 25, in <module>
from ..utils.sparsefuncs import (inplace_column_scale,
ImportError: cannot import name inplace_column_scale
回答1:
Try this within your terminal:
conda install -c anaconda scikit-learn=0.18.1
If it does not work go to your terminal and try:
conda update anaconda
After the update is complete, then try the first bit of code again Hopefully it works
回答2:
please see this question. ImportError: cannot import name inplace_column_scale.
I think you face the same problem. There are several ways to solve it.
For windows. delete python27\Lib\site-packages\sklearn\utils\sparsefuncs.pyd.
For mac and linux, delete /usr/local/lib/python2.7/site-packages/sklearn/utils/sparsefuncs.so.
If you use anaconda, delete anaconda/lib/python2.7/site-packages/sklearn/utils/sparsefuncs.so
reinstall the sklearn. pip uninstall scikit-learn pip install scikit-learn
来源:https://stackoverflow.com/questions/41843007/sklearn-0-17-1-importerror-cannot-import-name-inplace-column-scale