7
import numpy as np
  File "/home/anirrudh/.virtualenvs/ml4t2/local/lib/python2.7/site-packages/numpy/__init__.py", line 180, in <module>
    from . import add_newdocs
  File "/home/anirrudh/.virtualenvs/ml4t2/local/lib/python2.7/site-packages/numpy/add_newdocs.py", line 13, in <module>
    from numpy.lib import add_newdoc
  File "/home/anirrudh/.virtualenvs/ml4t2/local/lib/python2.7/site-packages/numpy/lib/__init__.py", line 8, in <module>
    from .type_check import *
  File "/home/anirrudh/.virtualenvs/ml4t2/local/lib/python2.7/site-packages/numpy/lib/type_check.py", line 11, in <module>
    import numpy.core.numeric as _nx
  File "/home/anirrudh/.virtualenvs/ml4t2/local/lib/python2.7/site-packages/numpy/core/__init__.py", line 57, in <module>
    from numpy.testing import Tester
  File "/home/anirrudh/.virtualenvs/ml4t2/local/lib/python2.7/site-packages/numpy/testing/__init__.py", line 14, in <module>
    from .utils import *
  File "/home/anirrudh/.virtualenvs/ml4t2/local/lib/python2.7/site-packages/numpy/testing/utils.py", line 15, in <module>
    from tempfile import mkdtemp
  File "/usr/lib/python2.7/tempfile.py", line 35, in <module>
    from random import Random as _Random
  File "/home/anirrudh/OMSCS/Courses/ML4T/ml4t/mc3_p2/random.py", line 5, in <module>
    import matplotlib.pyplot as plt
  File "/home/anirrudh/.virtualenvs/ml4t2/local/lib/python2.7/site-packages/matplotlib/__init__.py", line 122, in <module>
    from matplotlib.cbook import is_string_like, mplDeprecation, dedent, get_label
  File "/home/anirrudh/.virtualenvs/ml4t2/local/lib/python2.7/site-packages/matplotlib/cbook.py", line 33, in <module>
    import numpy.ma as ma
  File "/home/anirrudh/.virtualenvs/ml4t2/local/lib/python2.7/site-packages/numpy/ma/__init__.py", line 44, in <module>
    from . import core
  File "/home/anirrudh/.virtualenvs/ml4t2/local/lib/python2.7/site-packages/numpy/ma/core.py", line 30, in <module>
    import numpy.core.umath as umath
AttributeError: 'module' object has no attribute 'core'

I am working on Ubuntu 14.04. I tried reinstalling numpy, created a new virtualenv, but it isn't helping. I get the same error outside the virtualenv as well. It stopped working suddenly. It was fine until a little while ago.

1
  • 5
    For those still scratching their heads, make sure that you delete any .pyc files that may be hiding in your project directory as well. Dec 6, 2015 at 21:05

5 Answers 5

21

(Answer posted on behalf of the OP).

Update: Resolved.

I had created a python file for one of my projects name random.py and when numpy is imported, it was calling this file instead of it's own library file hence resulting in the error. I had to delete/rename random.py which I created and that fixed the issue.

3
  • 4
    What are the chances that I made exactly the same mistake! Sep 6, 2017 at 9:10
  • 1
    @RohanSaxena 100% Feb 19, 2018 at 9:59
  • 1
    what are the changes that I also made the same mistake ! Thanks, it resolved my problem after renaming the random.py script in my project folder. I was using Visual Studio Code editor with my project folder open. With the random.py in the project folder it was not allowing me to do import numpy or import pandas even in the python command prompt.
    – pravi
    Aug 28, 2018 at 11:42
2

Try running it in Python 2 instead of Python 3 - you may have the older version of Spark

2

This happened to me in Windows with Anaconda. I fixed it by removing the python3 path from the environment variable PATH.

0

Another common problem here (which I had)...check to make sure you dont have a PYTHONPATH env var pointing to a different version of python site-packages (this happened because I updated my python version and didn't change this...it loads from PYTHONPATH first).

0

It happened to me in a specific ipynb, once I crated a copy of the notebook with a different name I was able to import numpy.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.