5

The following code executed from an IDLE window produces an error shown below.

 import numpy as np
 testarray = np.array([1,2,3], int)

Here is the error...

 Traceback (most recent call last):
   File "C:\Test\numpy.py", line 1, in <module>
     import numpy as np
   File "C:\Test\numpy.py", line 2, in <module>
     testarray = np.array([1,2,3], int)
 AttributeError: 'module' object has no attribute 'array'
 >>> 

If I do the same thing in the Shell, it works just fine...

 >>> import numpy as np
 >>> testarray = np.array([1,2,3], int)
 >>> testarray
 array([1, 2, 3])
 >>> 

This has been holding me up all day... anyone know how fix it? Perhaps I'm doing something wrong.

Note: If I just execute the code above without the testarray, no error gets returned.

3
  • It works for me in both IDLE and Shell - even with testarray. user2357112 post - that would do it too. Commented Jul 29, 2013 at 23:40
  • @sihrc -- I am completely stumped with this. I have no idea why it's not working. I did just add how eliminating the testarray = np.array([1,2,3], int) did not return an error. Commented Jul 29, 2013 at 23:41
  • check for numpy.py in your working directory as user2357112 suggested Commented Jul 29, 2013 at 23:42

1 Answer 1

10

You named a file numpy.py. Python sees that in the module search path and thinks it's the implementation of numpy. Pick a different name.

Sign up to request clarification or add additional context in comments.

2 Comments

This was exactly it. Thank you! I will accept this when the time limit is up.
I should have seen this coming from a mile away, it said line 1.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.