-2
from sklearn.datasets import load_iris
def test():
    iris = load_iris()

the code is above,my python version is python 3.6,sklearn version is 0.19.1。the error messages is below:

Traceback (most recent call last): File "E:/pycharm/PyCharm 2017.2.3/workspace/machine-learning/DecisionTree.py", line 10, in from sklearn.datasets import load_wine File "C:\Users\10649\AppData\Roaming\Python\Python36\site-packages\sklearn\datasets__init__.py", line 25, in from .mldata import fetch_mldata, mldata_filename File "C:\Users\10649\AppData\Roaming\Python\Python36\site-packages\sklearn\datasets\mldata.py", line 12, in from urllib2 import HTTPError File "E:\python36\lib\site-packages\urllib2.py", line 220 raise AttributeError, attr ^ SyntaxError: invalid syntax

is this show that sklearn.datasets can't use in python3? help me, please

Aditi
  • 820
  • 11
  • 27
  • `raise AttributeError, attr` is a Python 2 syntax. It can't be executed by a Python 3 interpreter. – DeepSpace Mar 12 '18 at 09:59
  • The error is in `urllib2` module. Maybe [this can help](https://stackoverflow.com/questions/2792650/import-error-no-module-name-urllib2) – Vivek Kumar Mar 12 '18 at 09:59
  • I'm not sure how but you somehow managed to install a Python 2 package (`urllib2`) to your Python 3.6 `site-packages` directory – DeepSpace Mar 12 '18 at 10:01

1 Answers1

1

Check the conformity between your libraries and your Python interpreter, you seem to be using a python2 package with python3.6

Pick either python version that suits your needs and bundle the appropriate scikit-learn package

You should be able to install the correct packages with these types of commands:

pip3 install --upgrade pip

pip install --user scikit-learn

You could also go down the path of using Anaconda if you are keen of that kind of tool.

I personnaly like Pipenv very much.

Dodge
  • 3,219
  • 3
  • 19
  • 38
Antry
  • 448
  • 3
  • 9