Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AttributeError with numpy in IDLE but not in Python Shell

Tags:

python

numpy

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.

like image 910
TravisVOX Avatar asked Jul 29 '13 23:07

TravisVOX


1 Answers

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.

like image 185
user2357112 supports Monica Avatar answered Oct 29 '22 21:10

user2357112 supports Monica