module 'numpy' has no attribute 'dtype'

Question:

When importing sklearn datasets eg.

from sklearn.datasets import fetch_mldata
from sklearn.datasets import fetch_openml

I get the error

Traceback (most recent call last):
  File "numbers.py", line 1, in <module>
    from sklearn.datasets import fetch_openml
  File "/anaconda2/envs/numbers/lib/python3.5/site-packages/sklearn/__init__.py", line 64, in <module>
    from .base import clone
  File "/anaconda2/envs/numbers/lib/python3.5/site-packages/sklearn/base.py", line 11, in <module>
    import numpy as np
  File "/anaconda2/envs/numbers/lib/python3.5/site-packages/numpy/__init__.py", line 142, in <module>
    from . import core
  File "/anaconda2/envs/numbers/lib/python3.5/site-packages/numpy/core/__init__.py", line 93, in <module>
    from . import numerictypes as nt
  File "/anaconda2/envs/numbers/lib/python3.5/site-packages/numpy/core/numerictypes.py", line 86, in <module>
    import numbers
  File "/Users/airocoop/repos/Numbers/numbers.py", line 1, in <module>
    from sklearn.datasets import fetch_openml
  File "/anaconda2/envs/numbers/lib/python3.5/site-packages/sklearn/datasets/__init__.py", line 6, in <module>
    from .base import load_breast_cancer
  File "/anaconda2/envs/numbers/lib/python3.5/site-packages/sklearn/datasets/base.py", line 20, in <module>
    from ..utils import Bunch
  File "/anaconda2/envs/numbers/lib/python3.5/site-packages/sklearn/utils/__init__.py", line 10, in <module>
    from scipy.sparse import issparse
  File "/anaconda2/envs/numbers/lib/python3.5/site-packages/scipy/__init__.py", line 72, in <module>
    from numpy.random import rand, randn
  File "/anaconda2/envs/numbers/lib/python3.5/site-packages/numpy/random/__init__.py", line 143, in <module>
    from .mtrand import *
  File "numpy.pxd", line 87, in init mtrand
AttributeError: module 'numpy' has no attribute 'dtype'

I am not sure why I get this

I don’t get this error when running things from a jupyter notebook, which is also weird. Any help on this issue would be greatly appreciated

Asked By: Joshua Vandenbor

||

Answers:

Broken installation.

Do this:

1)

conda install numpy=1.13

or 2)

pip install numpy --upgrade
Answered By: seralouk

I figured this out. The answer is that the file I was running was named numbers.py. This screws the whole thing up. If you have this problem check to make sure you don’t have a file in the directory called numbers.py

Easy way to check is move the file with the import statement to a different directory and try running it.

Answered By: Joshua Vandenbor