2
votes

I just installed sklearn using pip. When I try to import anything I get an AttributeError.

import sklearn # No error

from sklearn import svm # AttributeError

from sklearn import datasets # Same AttributeError

Full output: Traceback (most recent call last): test.py", line 1, in
from sklearn import cluster File "AppData\Local\Programs\Python\Python37-32\lib\site-packages\sklearn\cluster__init__.py", line 6, in
from .spectral import spectral_clustering, SpectralClustering File "AppData\Local\Programs\Python\Python37-32\lib\site-packages\sklearn\cluster\spectral.py", line 15, in
from ..metrics.pairwise import pairwise_kernels File "AppData\Local\Programs\Python\Python37-32\lib\site-packages\sklearn\metrics__init__.py", line 7, in
from .ranking import auc File "AppData\Local\Programs\Python\Python37-32\lib\site-packages\sklearn\metrics\ranking.py", line 27, in
from scipy.stats import rankdata File "AppData\Local\Programs\Python\Python37-32\lib\site-packages\scipy\stats__init__.py", line 345, in
from .stats import * File "AppData\Local\Programs\Python\Python37-32\lib\site-packages\scipy\stats\stats.py", line 171, in
from . import distributions File "AppData\Local\Programs\Python\Python37-32\lib\site-packages\scipy\stats\distributions.py", line 13, in
from . import _continuous_distns File "AppData\Local\Programs\Python\Python37-32\lib\site-packages\scipy\stats_continuous_distns.py", line 113, in
class norm_gen(rv_continuous): File "AppData\Local\Programs\Python\Python37-32\lib\site-packages\scipy\stats_continuous_distns.py", line 175, in norm_gen optimizer argument is ignored.\n\n""") File "AppData\Local\Programs\Python\Python37-32\lib\site-packages\scipy\misc\doccer.py", line 159, in _doc start_of_notes = cls_docstring.find(notes_header) AttributeError: 'NoneType' object has no attribute 'find'

# From doccer.py
def _doc(func):
    cls_docstring = getattr(cls, func.__name__).__doc__
    notes_header = '        Notes\n        -----\n'
    # XXX The following assumes that there is a Notes section.
    start_of_notes = cls_docstring.find(notes_header) # This is line 159
    end_of_notes = cls_docstring.find('        References\n')
    if end_of_notes == -1:
        end_of_notes = cls_docstring.find('        Examples\n')
        if end_of_notes == -1:
            end_of_notes = len(cls_docstring)
    func.__doc__ = (cls_docstring[:start_of_notes + len(notes_header)] +
                    notes +
                    cls_docstring[end_of_notes:])
    return func
return _doc

I'm using Python 3.7.1

Does anyone have an idea how this problem can be fixed?
I'm not sure what more information to include, so if you need more information please tell me to do so.

EDIT1:
I tried doing the exact same thing on my pc, and it works just fine. This problem only occurs when using my laptop.

2
Are you running Python with -OO on? If so, try turning off -OO. - user2357112 supports Monica
It would help to post the complete, exact error message, including full stack trace. - user2357112 supports Monica
Could you elaborate? I'm not sure what -oo is, and how do I turn it off? - Doey
-OO is a command-line option. Depending on how you're running Python, you may need to check IDE options or something similar to see what the command line options look like. - user2357112 supports Monica
Type import sklearn and the sklearn.__version__. What is the output ? - seralouk

2 Answers

0
votes

This seems to be a broken installation probelm.

Try these please:

Open your terminal (cmd) and try these before you try to import the sklearn.

pip3 install -U scikit-learn

Also make sure your have numpy and scipy:

pip3 install numpy 
pip3 install scipy

Edit 1:

Try also this:

pip uninstall scikit-learn
sudo pip install scikit-learn
0
votes

My current user has a whitespace in the c-drive user name. I tried making another user on my laptop without that whitespace, downloaded python 3.7.1 and pip installed scikit-learn and it worked just fine!