[PYTHON] scikit-learn import error

What This article is an article that solves the error that occurred when importing scikit-learn.

Problem I got the following error when running the program below

sklearn.py



from sklearn import datasets
import numpy as np

#Load Iris dataset
iris = datasets.load_iris()

When I run this code, I get an error if I can't read dataset from sklearn on the bottom line.

File "sklearn.py", line 1, in <module>
    from sklearn import datasets
  File "/Users/apple/python/sklearn.py", line 1, in <module>
    from sklearn import datasets
ImportError: cannot import name 'datasets' from partially initialized module 'sklearn' (most likely due to a circular import) (/Users/apple/python/sklearn.py)

Solution I solved it by changing the file name to something other than sklearn. It seems that it was imported itself because the file name is sklearn.

Detail I ran the following two lines to check where the file was read from

import sklearn
print(sklearn.__file__)

I was reading myself lol

/Users/apple/sklearn.py

So I changed the file name and it worked

Recommended Posts

scikit-learn import error
ROS Python-Own service import error
Solution for scikit-learn (sklearn) fetch_mldata error
Resolve VS Code unresolved import error
An error occurred in scikit-learn imputer
About import error of PyQt5.QtWidgets (Anaconda)
I get an error with import pandas.
Import error even though python is installed
Revisited scikit-learn
Error recording
windows7 / python3.3 / virtualenv / cx_Freeze / Import Error / MAXREPEAT
About import
Homebrew error
Import Error in Python3: No module named'xxxxx'
An error occurs when trying to import scikit-learn after connecting to Oracle with SQLAlchemy
Solution for "Import Error: No module named requests"
Could not import C error in GO environment