简体   繁体   中英

ImportError: cannot import name '__version__' from 'sklearn' (unknown location)

Windows laptop, using jupyter notebook

because of other errors I was having, I recently had to uninstall and re-install a bunch of packages (pip, jupyter notebook, tensorflow, sklearn + don't remember the others but all were python related). Now, I'm getting this error. Anyone know how to fix it? Thanks!

ImportError                               Traceback (most recent call last)
<timed exec> in <module>

~\Documents\UCSDproject\Interactive Framework\Framework_functions_modified.py in <module>
     16 import tensorflow as tf
     17 import sklearn
---> 18 from sklearn.cluster import KMeans
     19 from sklearn.metrics import silhouette_score
     20 import os, glob, shutil, math

~\anaconda3\lib\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, estimate_bandwidth, get_bin_seeds
      8 from ._affinity_propagation import affinity_propagation, AffinityPropagation

~\anaconda3\lib\site-packages\sklearn\cluster\_spectral.py in <module>
     10 import numpy as np
     11 
---> 12 from ..base import BaseEstimator, ClusterMixin
     13 from ..utils import check_random_state, as_float_array
     14 from ..utils.deprecation import deprecated

~\anaconda3\lib\site-packages\sklearn\base.py in <module>
     13 import numpy as np
     14 
---> 15 from . import __version__
     16 from ._config import get_config
     17 from .utils import _IS_32BIT

ImportError: cannot import name '__version__' from 'sklearn' (unknown location)

Also, not sure if this is related, but I get the following warning in my commandprompt everytime I try to install a program.

WARNING: Ignoring invalid distribution -umba (c:\users\user\anaconda3\lib\site-packages)
WARNING: Ignoring invalid distribution -lotly (c:\users\user\anaconda3\lib\site-packages)
WARNING: Ignoring invalid distribution -umba (c:\users\user\anaconda3\lib\site-packages)
WARNING: Ignoring invalid distribution -lotly (c:\users\user\anaconda3\lib\site-packages)
WARNING: Ignoring invalid distribution -umba (c:\users\user\anaconda3\lib\site-packages)
WARNING: Ignoring invalid distribution -lotly (c:\users\user\anaconda3\lib\site-packages)

So, turns out the warnings I was getting were related to the import error. I went into the site-packages directory & deleted all folders with ~ in front of them & then my code worked.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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