0
from sklearn import datasets

When running the above code, I got an error:

`Traceback` (most recent call last):
  File "perceptron_ml.py", line 2, in <module>
    from sklearn import datasets
  File "/home/remember/.local/lib/python3.6/site-packages/sklearn/datasets/__init__.py", line 22, in <module>
    from ._twenty_newsgroups import fetch_20newsgroups
  File "/home/remember/.local/lib/python3.6/site-packages/sklearn/datasets/_twenty_newsgroups.py", line 45, in <module>
    from ..feature_extraction.text import CountVectorizer
  File "/home/remember/.local/lib/python3.6/site-packages/sklearn/feature_extraction/__init__.py", line 8, in <module>
    from ._hashing import FeatureHasher
ImportError: cannot import name 'FeatureHasher'

Ubuntu: 18.04, Python: 3.6.9, Numpy: 1.17.4, scikit-learn: 0.22

moath naji
  • 663
  • 1
  • 4
  • 20
Wanghz
  • 305
  • 2
  • 12

1 Answers1

0

The error is due to a glitch happening during the update due to pip. Related SO post is https://stackoverflow.com/a/59355676/6513708

But long story short, you need to remove the following files which were let by pip during the update:

  • ~/.local/lib/python3.6/site-packages/sklearn/decomposition/_online_lda.cpython-36m-x86_64-linux-gnu.so
  • ~/.local/lib/python3.6/site-packages/sklearn/feature_extraction/_hashing.cpython-36m-x86_64-linux-gnu.so
  • ~/.local/lib/python3.6/site-packages/sklearn/datasets/_svmlight_format.cpython-36m-x86_64-linux-gnu.so
glemaitre
  • 963
  • 6
  • 7
  • Thank you. That does show me the way to solve the problem. I remove the two files you show, and get another error: `ImportError: cannot import name 'load_svmlight_file'`. Then I remove the file `~/.local/lib/python3.6/site-packages/sklearn/datasets/_svmlight_format.cpython-36m-x86_64-linux-gnu.so` and succeed. Thank you again! – Wanghz Dec 19 '19 at 02:09
  • Thanks, I will edit my post to add this file as well. – glemaitre Dec 19 '19 at 10:21