Importing sklearn.cluster throws ImportError
See original GitHub issueWhen I try to import the sklearn.cluster submodule the following Exception is raised:
ImportError: cannot import name 'k_means'
Steps/Code to Reproduce
I am running Python 3.6.9 with scikit-learn 0.22 on an Ubuntu 18.04. A single import statement is enough to trigger that behavior for me:
import sklearn.cluster
Error Message
That’s the output I get:
ImportError Traceback (most recent call last) <ipython-input-23-c8a0f0fed13e> in <module>() ----> 1 import sklearn.cluster
/home/XXX/.local/lib/python3.6/site-packages/sklearn/cluster/init.py in <module>() 4 “”" 5 ----> 6 from ._spectral import spectral_clustering, SpectralClustering 7 from ._mean_shift import (mean_shift, MeanShift, 8 estimate_bandwidth, get_bin_seeds)
/home/XXX/.local/lib/python3.6/site-packages/sklearn/cluster/_spectral.py in <module>() 16 from …neighbors import kneighbors_graph, NearestNeighbors 17 from …manifold import spectral_embedding —> 18 from ._k_means import k_means 19 20
ImportError: cannot import name ‘k_means’
Versions
Output of sklearn.show_versions()
:
System: python: 3.6.9 (default, Nov 7 2019, 10:44:02) [GCC 8.3.0] executable: /usr/bin/python3 machine: Linux-5.0.0-37-generic-x86_64-with-Ubuntu-18.04-bionic
Python dependencies: pip: 19.3.1 setuptools: 45.0.0 sklearn: 0.22 numpy: 1.18.1 scipy: 1.4.1 Cython: None pandas: 0.25.3 matplotlib: 3.1.2 joblib: 0.14.1
Built with OpenMP: True
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:8 (4 by maintainers)
Hey @glemaitre, so I uninstalled scikit-learn via pip3 and re-installed it, problem has gone away! Even though we didn’t get to the bottom of this (why did some submodules work others not), I think we can close this?!
You should not do that. I am pasting the snippet of documentation and lock this thread.