can't use scikit-learn - “AttributeError: 'module' object has no attribute …”

后端 未结 9 630
失恋的感觉
失恋的感觉 2020-12-31 02:57

I\'m trying to follow this tutorial of scikit-learn (linear regression).

I\'ve installed scikit through pip install -U scikit-learn, I use python 2.7 an

相关标签:
9条回答
  • 2020-12-31 03:45

    I had a similar problem and tried troubleshooting based on this article by Nick Coghlan since none of the suggested answers seemed to fix my problem.

    I fell into the so-called "Double Import trap". what I had was something like:

    import sklearn
    import sklearn.preprocessing
    

    by removing one of the imports and resetting my workspace I managed to fix the problem.

    0 讨论(0)
  • 2020-12-31 03:48

    I faced same issue but then i realized that my program name was sklearn.py . In case if any one sees this type of error also check that you program name is not same as the package name , or else you will get module object has no attribute error, as in the question .

    0 讨论(0)
  • 2020-12-31 03:53

    It seems that the package loaded from sklearn were the one from the distribution library and not the one installed from pip. Solution for me (debian) was to reinstall the pip package. This can be checked with:

    import sklearn
    sklearn.__path__
    

    If this shows /usr/lib/python/, then is it using the distribution.

    The problem got solved by uninstalling and reinstalling sklearn.

     $ pip uninstall scikit-learn
     $ pip install scikit-learn
    
    0 讨论(0)
提交回复
热议问题