在IDLE中带有numpy的AttributeError,但在Python Shell中没有 [英] AttributeError with numpy in IDLE but not in Python Shell

查看:58
本文介绍了在IDLE中带有numpy的AttributeError,但在Python Shell中没有的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从IDLE窗口执行的以下代码产生如下所示的错误.

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

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

这是错误...

 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.

注意:如果我只是在没有testarray的情况下执行上述代码,则不会返回任何错误.

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

推荐答案

您已将文件命名为numpy.py. Python在模块搜索路径中看到了这一点,并认为这是numpy的实现.选择其他名称.

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.

这篇关于在IDLE中带有numpy的AttributeError,但在Python Shell中没有的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆