shaare.it

AttributeError: module 'numpy' has no attribute 'foo'

7 Dec 2025

1 min read

AttributeError: module ‘numpy’ has no attribute

$ python -c "import numpy as np; np.foo()"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
AttributeError: module 'numpy' has no attribute 'foo'

Why this happens

The attribute or function doesn’t exist in NumPy (typo, wrong version) or you shadowed the numpy name with a local file named numpy.py.

Fix

Check spelling, update NumPy if the feature is added in newer versions, and ensure no local modules shadow NumPy. Rename local files if necessary.

Wrong code

import numpy as np
np.foo()

Fixed code

import numpy as np
print(np.array([1,2]))

# If you intended a different function, use the correct one, e.g. np.flip, np.mean, etc.