AttributeError with numpy in IDLE but not in Python shell

The following code executed from the IDLE window causes the error shown below.

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

Here is the mistake ...

  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 in the shell, it works fine ...

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

It keeps me all day ... does anyone know how to fix this? Maybe I'm doing something wrong.

Note. If I just executed the code above without testarray, the error will not be returned.

+4
source share
1 answer

You named the file numpy.py . Python sees this in the module search path and considers it a numpy implementation. Choose a different name.

+8
source

Source: https://habr.com/ru/post/1494165/


All Articles