3

I know there are several similar questions asked, but mine still remains unanswered.

Here's the problem. I used the command python3 -m pip3 install -U scikit-learn to install sklearn, numpy, and scipy. However, when I run:

import sklearn
from sklearn.linear_model import LogisticRegression

in my file, I got an error message like:

Traceback (most recent call last):
File "sklearn.py", line 4, in <module>
import sklearn
from sklearn.linear_model import LogisticRegression
ModuleNotFoundError: No module named 'sklearn.linear_model'; 'sklearn' is not a package

And strangely, when I run

import sklearn

everything is fine without any error.

In fact, I can't use any of the attributes of sklearn, and I can only import sklearn but I can't do anything.

By the way, I run my file on MAC OS terminal with python3 command.

CHIResearcher
  • 55
  • 1
  • 7

1 Answers1

13

your file name is sklearn.py when you try to import stuff, it looks at that file, which (I assume) doesn't have any linear_model object. Change your filename to something like my_sklearn_sandbox.py to avoid this ambiguity

Mohammad Athar
  • 1,953
  • 1
  • 15
  • 31