Can't import 'datasets' with scikit-learn
<p>I just installed Python (tried both 3.5.2 and 2.7.12 with the exact same result). I've tried Googling it and looking through issues but can't find anything on it.</p>

<p>The code I'm trying to run is simply the beginning of the basic tutorial:</p>

<pre><code>from sklearn import datasets
iris = datasets.load_iris()
digits = datasets.load_digits()
</code></pre>

<p>The error is <code>ImportError: cannot import name 'datasets'</code>.</p>

<p>I've tried re-installing everything. Same result over and over again. I'm on a Macbook with El Capitan which is newly installed as well.</p>

<p>I installed Python with pyenv, and scipy and numpy through pip. I've also upgraded pip, by the way, to the latest version.</p>

<pre><code>import _frozen_importlib # frozen
import _imp # builtin
import sys # builtin
import '_warnings' # &lt;class '_frozen_importlib.BuiltinImporter'&gt;
import '_thread' # &lt;class '_frozen_importlib.BuiltinImporter'&gt;
import '_weakref' # &lt;class '_frozen_importlib.BuiltinImporter'&gt;
import '_frozen_importlib_external' # &lt;class '_frozen_importlib.FrozenImporter'&gt;
import '_io' # &lt;class '_frozen_importlib.BuiltinImporter'&gt;
import 'marshal' # &lt;class '_frozen_importlib.BuiltinImporter'&gt;
import 'posix' # &lt;class '_frozen_importlib.BuiltinImporter'&gt;
import _thread # previously loaded ('_thread')
import '_thread' # &lt;class '_frozen_importlib.BuiltinImporter'&gt;
import _weakref # previously loaded ('_weakref')
import '_weakref' # &lt;class '_frozen_importlib.BuiltinImporter'&gt;
# installing zipimport hook
import 'zipimport' # &lt;class '_frozen_importlib.BuiltinImporter'&gt;
# installed zipimport hook
# /Users/fredrik/.pyenv/versions/3.5.2/lib/python3.5/encodings/__pycache__/__init__.cpython-35.pyc matches /Users/fredrik/.pyenv/versions/3.5.2/lib/python3.5/encodings/__init__.py
# code object from '/Users/fredrik/.pyenv/versions/3.5.2/lib/python3.5/encodings/__pycache__/__init__.cpython-35.pyc'
# /Users/fredrik/.pyenv/versions/3.5.2/lib/python3.5/__pycache__/codecs.cpython-35.pyc matches /Users/fredrik/.pyenv/versions/3.5.2/lib/python3.5/codecs.py
# code object from '/Users/fredrik/.pyenv/versions/3.5.2/lib/python3.5/__pycache__/codecs.cpython-35.pyc'
import '_codecs' # &lt;class '_frozen_importlib.BuiltinImporter'&gt;
import 'codecs' # &lt;_frozen_importlib_external.SourceFileLoader object at 0x108ac7390&gt;
# /Users/fredrik/.pyenv/versions/3.5.2/lib/python3.5/encodings/__pycache__/aliases.cpython-35.pyc matches /Users/fredrik/.pyenv/versions/3.5.2/lib/python3.5/encodings/aliases.py
# code object from '/Users/fredrik/.pyenv/versions/3.5.2/lib/python3.5/encodings/__pycache__/aliases.cpython-35.pyc'
import 'encodings.aliases' # &lt;_frozen_importlib_external.SourceFileLoader object at 0x108af7f60&gt;
import 'encodings' # &lt;_frozen_importlib_external.SourceFileLoader object at 0x108ac0f60&gt;
# /Users/fredrik/.pyenv/versions/3.5.2/lib/python3.5/encodings/__pycache__/utf_8.cpython-35.pyc matches /Users/fredrik/.pyenv/versions/3.5.2/lib/python3.5/encodings/utf_8.py
# code object from '/Users/fredrik/.pyenv/versions/3.5.2/lib/python3.5/encodings/__pycache__/utf_8.cpython-35.pyc'
import 'encodings.utf_8' # &lt;_frozen_importlib_external.SourceFileLoader object at 0x108b07d30&gt;
import '_signal' # &lt;class '_frozen_importlib.BuiltinImporter'&gt;
# /Users/fredrik/.pyenv/versions/3.5.2/lib/python3.5/encodings/__pycache__/latin_1.cpython-35.pyc matches /Users/fredrik/.pyenv/versions/3.5.2/lib/python3.5/encodings/latin_1.py
# code object from '/Users/fredrik/.pyenv/versions/3.5.2/lib/python3.5/encodings/__pycache__/latin_1.cpython-35.pyc'
import 'encodings.latin_1' # &lt;_frozen_importlib_external.SourceFileLoader object at 0x108af97f0&gt;
# /Users/fredrik/.pyenv/versions/3.5.2/lib/python3.5/__pycache__/io.cpython-35.pyc matches /Users/fredrik/.pyenv/versions/3.5.2/lib/python3.5/io.py
# code object from '/Users/fredrik/.pyenv/versions/3.5.2/lib/python3.5/__pycache__/io.cpython-35.pyc'
# /Users/fredrik/.pyenv/versions/3.5.2/lib/python3.5/__pycache__/abc.cpython-35.pyc matches /Users/fredrik/.pyenv/versions/3.5.2/lib/python3.5/abc.py
# code object from '/Users/fredrik/.pyenv/versions/3.5.2/lib/python3.5/__pycache__/abc.cpython-35.pyc'
# /Users/fredrik/.pyenv/versions/3.5.2/lib/python3.5/__pycache__/_weakrefset.cpython-35.pyc matches /Users/fredrik/.pyenv/versions/3.5.2/lib/python3.5/_weakrefset.py
# code object from '/Users/fredrik/.pyenv/versions/3.5.2/lib/python3.5/__pycache__/_weakrefset.cpython-35.pyc'
import '_weakrefset' # &lt;_frozen_importlib_external.SourceFileLoader object at 0x108b10470&gt;
import 'abc' # &lt;_frozen_importlib_external.SourceFileLoader object at 0x108af9c50&gt;
import 'io' # &lt;_frozen_importlib_external.SourceFileLoader object at 0x108af99e8&gt;
# /Users/fredrik/.pyenv/versions/3.5.2/lib/python3.5/__pycache__/site.cpython-35.pyc matches /Users/fredrik/.pyenv/versions/3.5.2/lib/python3.5/site.py
# code object from '/Users/fredrik/.pyenv/versions/3.5.2/lib/python3.5/__pycache__/site.cpython-35.pyc'
# /Users/fredrik/.pyenv/versions/3.5.2/lib/python3.5/__pycache__/os.cpython-35.pyc matches /Users/fredrik/.pyenv/versions/3.5.2/lib/python3.5/os.py
# code object from '/Users/fredrik/.pyenv/versions/3.5.2/lib/python3.5/__pycache__/os.cpython-35.pyc'
import 'errno' # &lt;class '_frozen_importlib.BuiltinImporter'&gt;
# /Users/fredrik/.pyenv/versions/3.5.2/lib/python3.5/__pycache__/stat.cpython-35.pyc matches /Users/fredrik/.pyenv/versions/3.5.2/lib/python3.5/stat.py
# code object from '/Users/fredrik/.pyenv/versions/3.5.2/lib/python3.5/__pycache__/stat.cpython-35.pyc'
import '_stat' # &lt;class '_frozen_importlib.BuiltinImporter'&gt;
import 'stat' # &lt;_frozen_importlib_external.SourceFileLoader object at 0x108b954a8&gt;
# /Users/fredrik/.pyenv/versions/3.5.2/lib/python3.5/__pycache__/posixpath.cpython-35.pyc matches /Users/fredrik/.pyenv/versions/3.5.2/lib/python3.5/posixpath.py
# code object from '/Users/fredrik/.pyenv/versions/3.5.2/lib/python3.5/__pycache__/posixpath.cpython-35.pyc'
# /Users/fredrik/.pyenv/versions/3.5.2/lib/python3.5/__pycache__/genericpath.cpython-35.pyc matches /Users/fredrik/.pyenv/versions/3.5.2/lib/python3.5/genericpath.py
# code object from '/Users/fredrik/.pyenv/versions/3.5.2/lib/python3.5/__pycache__/genericpath.cpython-35.pyc'
import 'genericpath' # &lt;_frozen_importlib_external.SourceFileLoader object at 0x108b97d30&gt;
import 'posixpath' # &lt;_frozen_importlib_external.SourceFileLoader object at 0x108b957f0&gt;
# /Users/fredrik/.pyenv/versions/3.5.2/lib/python3.5/__pycache__/_collections_abc.cpython-35.pyc matches /Users/fredrik/.pyenv/versions/3.5.2/lib/python3.5/_collections_abc.py
# code object from '/Users/fredrik/.pyenv/versions/3.5.2/lib/python3.5/__pycache__/_collections_abc.cpython-35.pyc'
import '_collections_abc' # &lt;_frozen_importlib_external.SourceFileLoader object at 0x108ba03c8&gt;
import 'os' # &lt;_frozen_importlib_external.SourceFileLoader object at 0x108b24278&gt;
# /Users/fredrik/.pyenv/versions/3.5.2/lib/python3.5/__pycache__/_sitebuiltins.cpython-35.pyc matches /Users/fredrik/.pyenv/versions/3.5.2/lib/python3.5/_sitebuiltins.py
# code object from '/Users/fredrik/.pyenv/versions/3.5.2/lib/python3.5/__pycache__/_sitebuiltins.cpython-35.pyc'
import '_sitebuiltins' # &lt;_frozen_importlib_external.SourceFileLoader object at 0x108b24550&gt;
# /Users/fredrik/.pyenv/versions/3.5.2/lib/python3.5/__pycache__/sysconfig.cpython-35.pyc matches /Users/fredrik/.pyenv/versions/3.5.2/lib/python3.5/sysconfig.py
# code object from '/Users/fredrik/.pyenv/versions/3.5.2/lib/python3.5/__pycache__/sysconfig.cpython-35.pyc'
import 'sysconfig' # &lt;_frozen_importlib_external.SourceFileLoader object at 0x108bd9668&gt;
# /Users/fredrik/.pyenv/versions/3.5.2/lib/python3.5/__pycache__/_sysconfigdata.cpython-35.pyc matches /Users/fredrik/.pyenv/versions/3.5.2/lib/python3.5/_sysconfigdata.py
# code object from '/Users/fredrik/.pyenv/versions/3.5.2/lib/python3.5/__pycache__/_sysconfigdata.cpython-35.pyc'
import '_sysconfigdata' # &lt;_frozen_importlib_external.SourceFileLoader object at 0x108bdff28&gt;
# /Users/fredrik/.pyenv/versions/3.5.2/lib/python3.5/__pycache__/_osx_support.cpython-35.pyc matches /Users/fredrik/.pyenv/versions/3.5.2/lib/python3.5/_osx_support.py
# code object from '/Users/fredrik/.pyenv/versions/3.5.2/lib/python3.5/__pycache__/_osx_support.cpython-35.pyc'
# /Users/fredrik/.pyenv/versions/3.5.2/lib/python3.5/__pycache__/re.cpython-35.pyc matches /Users/fredrik/.pyenv/versions/3.5.2/lib/python3.5/re.py
# code object from '/Users/fredrik/.pyenv/versions/3.5.2/lib/python3.5/__pycache__/re.cpython-35.pyc'
# /Users/fredrik/.pyenv/versions/3.5.2/lib/python3.5/__pycache__/sre_compile.cpython-35.pyc matches /Users/fredrik/.pyenv/versions/3.5.2/lib/python3.5/sre_compile.py
# code object from '/Users/fredrik/.pyenv/versions/3.5.2/lib/python3.5/__pycache__/sre_compile.cpython-35.pyc'
import '_sre' # &lt;class '_frozen_importlib.BuiltinImporter'&gt;
# /Users/fredrik/.pyenv/versions/3.5.2/lib/python3.5/__pycache__/sre_parse.cpython-35.pyc matches /Users/fredrik/.pyenv/versions/3.5.2/lib/python3.5/sre_parse.py
# code object from '/Users/fredrik/.pyenv/versions/3.5.2/lib/python3.5/__pycache__/sre_parse.cpython-35.pyc'
# /Users/fredrik/.pyenv/versions/3.5.2/lib/python3.5/__pycache__/sre_constants.cpython-35.pyc matches /Users/fredrik/.pyenv/versions/3.5.2/lib/python3.5/sre_constants.py
# code object from '/Users/fredrik/.pyenv/versions/3.5.2/lib/python3.5/__pycache__/sre_constants.cpython-35.pyc'
import 'sre_constants' # &lt;_frozen_importlib_external.SourceFileLoader object at 0x108c0a6a0&gt;
import 'sre_parse' # &lt;_frozen_importlib_external.SourceFileLoader object at 0x108bfed68&gt;
import 'sre_compile' # &lt;_frozen_importlib_external.SourceFileLoader object at 0x108bf5da0&gt;
import '_locale' # &lt;class '_frozen_importlib.BuiltinImporter'&gt;
# /Users/fredrik/.pyenv/versions/3.5.2/lib/python3.5/__pycache__/copyreg.cpython-35.pyc matches /Users/fredrik/.pyenv/versions/3.5.2/lib/python3.5/copyreg.py
# code object from '/Users/fredrik/.pyenv/versions/3.5.2/lib/python3.5/__pycache__/copyreg.cpython-35.pyc'
import 'copyreg' # &lt;_frozen_importlib_external.SourceFileLoader object at 0x108c47470&gt;
import 're' # &lt;_frozen_importlib_external.SourceFileLoader object at 0x108bf1eb8&gt;
import '_osx_support' # &lt;_frozen_importlib_external.SourceFileLoader object at 0x108bf1080&gt;
# /Users/fredrik/.pyenv/versions/3.5.2/lib/python3.5/__pycache__/_bootlocale.cpython-35.pyc matches /Users/fredrik/.pyenv/versions/3.5.2/lib/python3.5/_bootlocale.py
# code object from '/Users/fredrik/.pyenv/versions/3.5.2/lib/python3.5/__pycache__/_bootlocale.cpython-35.pyc'
import '_bootlocale' # &lt;_frozen_importlib_external.SourceFileLoader object at 0x108c47390&gt;
import 'site' # &lt;_frozen_importlib_external.SourceFileLoader object at 0x108b17d68&gt;
Python 3.5.2 (default, Aug 30 2016, 00:56:52) 
[GCC 4.2.1 Compatible Apple LLVM 7.3.0 (clang-703.0.31)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
# /Users/fredrik/code/scikit-learn/__pycache__/sklearn.cpython-35.pyc matches /Users/fredrik/code/scikit-learn/sklearn.py
# code object from '/Users/fredrik/code/scikit-learn/__pycache__/sklearn.cpython-35.pyc'
Traceback (most recent call last):
  File "sklearn.py", line 1, in &lt;module&gt;
    from sklearn import datasets
  File "&lt;frozen importlib._bootstrap&gt;", line 969, in _find_and_load
  File "&lt;frozen importlib._bootstrap&gt;", line 958, in _find_and_load_unlocked
  File "&lt;frozen importlib._bootstrap&gt;", line 673, in _load_unlocked
  File "&lt;frozen importlib._bootstrap_external&gt;", line 665, in exec_module
  File "&lt;frozen importlib._bootstrap&gt;", line 222, in _call_with_frames_removed
  File "/Users/fredrik/code/scikit-learn/sklearn.py", line 1, in &lt;module&gt;
    from sklearn import datasets
ImportError: cannot import name 'datasets'
# clear builtins._
# clear sys.path
# clear sys.argv
# clear sys.ps1
# clear sys.ps2
# clear sys.last_type
# clear sys.last_value
# clear sys.last_traceback
# destroy sklearn
# clear sys.path_hooks
# clear sys.path_importer_cache
# clear sys.meta_path
# clear sys.__interactivehook__
# clear sys.flags
# clear sys.float_info
# restore sys.stdin
# restore sys.stdout
# restore sys.stderr
# cleanup[2] removing encodings.latin_1
# cleanup[2] removing _locale
# cleanup[2] removing __main__
# destroy __main__
# cleanup[2] removing os.path
# cleanup[2] removing _sysconfigdata
# destroy _sysconfigdata
# cleanup[2] removing _bootlocale
# destroy _bootlocale
# cleanup[2] removing sysconfig
# destroy sysconfig
# cleanup[2] removing zipimport
# cleanup[2] removing sre_compile
# cleanup[2] removing _stat
# cleanup[2] removing _collections_abc
# destroy _collections_abc
# cleanup[2] removing posixpath
# cleanup[2] removing _imp
# cleanup[2] removing _weakrefset
# destroy _weakrefset
# cleanup[2] removing marshal
# cleanup[2] removing _frozen_importlib_external
# cleanup[2] removing posix
# cleanup[2] removing sre_constants
# destroy sre_constants
# cleanup[2] removing builtins
# cleanup[2] removing site
# destroy site
# cleanup[2] removing sre_parse
# cleanup[2] removing _weakref
# cleanup[2] removing encodings
# destroy encodings
# cleanup[2] removing errno
# cleanup[2] removing encodings.utf_8
# cleanup[2] removing _codecs
# cleanup[2] removing os
# cleanup[2] removing _frozen_importlib
# cleanup[2] removing _warnings
# cleanup[2] removing sys
# cleanup[2] removing codecs
# cleanup[2] removing abc
# cleanup[2] removing _io
# cleanup[2] removing stat
# cleanup[2] removing encodings.aliases
# cleanup[2] removing copyreg
# cleanup[2] removing io
# destroy io
# destroy abc
# cleanup[2] removing _osx_support
# destroy _osx_support
# cleanup[2] removing _thread
# cleanup[2] removing _sre
# cleanup[2] removing genericpath
# cleanup[2] removing re
# cleanup[2] removing _signal
# cleanup[2] removing _sitebuiltins
# destroy zipimport
# destroy _signal
# destroy _sitebuiltins
# destroy posixpath
# destroy errno
# destroy _stat
# destroy genericpath
# destroy stat
# destroy os
# destroy re
# destroy sre_compile
# destroy copyreg
# destroy sre_parse
# destroy _sre
# destroy _locale
# cleanup[3] wiping encodings.latin_1
# cleanup[3] wiping _imp
# cleanup[3] wiping marshal
# cleanup[3] wiping _frozen_importlib_external
# destroy marshal
# cleanup[3] wiping posix
# destroy posix
# cleanup[3] wiping _weakref
# cleanup[3] wiping encodings.utf_8
# cleanup[3] wiping _codecs
# cleanup[3] wiping _frozen_importlib
# destroy _frozen_importlib_external
# destroy _weakref
# destroy _imp
# cleanup[3] wiping _warnings
# destroy _warnings
# cleanup[3] wiping codecs
# cleanup[3] wiping _io
# destroy io
# cleanup[3] wiping encodings.aliases
# cleanup[3] wiping _thread
# destroy _thread
# cleanup[3] wiping sys
# cleanup[3] wiping builtins
# destroy _frozen_importlib
</code></pre>

<p>The error is caused from the file that you have named <code>/Users/fredrik/code/scikit-learn/sklearn.py</code></p>

<p>The <code>sklearn</code> library is being overridden by your local file, so you just need to rename the <code>sklearn.py</code> file in your project to something else and it should work.</p>

python numpy scipy scikit-learn