简体   繁体   中英

ImportError when importing sklearn

I am getting started with machine learning in Python. So I was reading a tutorial on how to get started. article asked me to install some necessary libraries including numpy , matplotlib , scipy , pandas and sklearn , I looked up in PyCharm interpreter settings and it showed me that It already have all of them, installed. But when I try to import them. Specifically, sklearn, it throws this error.

Traceback (most recent call last):
  File "C:/Users/iMacPro 2K19/PycharmProjects/Machine Learning/main.py", line 6, in <module>
    import sklearn
  File "C:\Users\iMacPro 2K19\AppData\Local\Programs\Python\Python37-32\lib\site-packages\sklearn\__init__.py", line 82, in <module>
    from .base import clone
  File "C:\Users\iMacPro 2K19\AppData\Local\Programs\Python\Python37-32\lib\site-packages\sklearn\base.py", line 20, in <module>
    from .utils import _IS_32BIT
  File "C:\Users\iMacPro 2K19\AppData\Local\Programs\Python\Python37-32\lib\site-packages\sklearn\utils\__init__.py", line 28, in <module>
    from .validation import (as_float_array,
ImportError: cannot import name 'as_float_array' from 'sklearn.utils.validation' (C:\Users\iMacPro 2K19\AppData\Local\Programs\Python\Python37-32\lib\site-packages\sklearn\utils\validation.py)

Process finished with exit code 1

if helpful, here's my code too..

import sys
import scipy
import numpy
import matplotlib
import pandas
import sklearn
# Python Version
print('Python {0}'.format(sys.version))
# scipy
print('scipy {0}'.format(scipy.__version__))
# numpy
print('numpy {0}'.format(numpy.__version__))
# matplotlib
print('matplotlib {0}'.format(matplotlib.__version__))
# pandas
print('pandas {0}'.format(pandas.__version__))
# sklearn
print('sklearn {0]'.format(sklearn.__version__))

I'm running win7 x64. python 3.7.3 , scipy 1.3.2 , numpy 1.17.4 , matplotlib 3.1.2 and pandas 0.25.3 . and someone also please tell me if sklearn and scikit-learn are different or both are just same with different names because i have sklearn version 0.0 and scikit-learn version 0.22.1 . and when importing I'm only able to import sklearn, scikit-learn does not show as available when trying to import. I don't think that there's any problem within the code. Maybe sklearn is not compatible with my version of python. I don't know for sure. Any help would be much appreciated. Thanks.

In the command promt try

pip install -U scikit-learn

After Try this code to test versions of your librarys into your python IDLE.

import sys
import scipy
import numpy
import matplotlib
import pandas
import sklearn
# Python Version
print('Python {0}'.format(sys.version))
# scipy
print('scipy {0}'.format(scipy.__version__))
# numpy
print('numpy {0}'.format(numpy.__version__))
# matplotlib
print('matplotlib {0}'.format(matplotlib.__version__))
# pandas
print('pandas {0}'.format(pandas.__version__))
# sklearn
print('sklearn {0}'.format(sklearn.__version__))

You can see in your terminal somthing with that in your otput console

Python 3.8.3 (default, Jul  2 2020, 17:30:36) [MSC v.1916 64 bit (AMD64)]
scipy 1.5.0
numpy 1.18.5
matplotlib 3.2.2
pandas 1.0.5
sklearn 0.23.1

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