"ModuleNotFoundError: 没有名为 'numpy.array' 的模块;'numpy' 不是一个包" [英] "ModuleNotFoundError: No module named 'numpy.array'; 'numpy' is not a package"

查看:61
本文介绍了"ModuleNotFoundError: 没有名为 'numpy.array' 的模块;'numpy' 不是一个包"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

代码:

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

错误:

Traceback (most recent call last):
  File "C:\Users\Jeffhacks\Desktop\np.py", line 1, in <module>
    import numpy as np
  File "C:\Users\Jeffhacks\Desktop\numpy.py", line 1, in <module>
    import numpy.array as np
ModuleNotFoundError: No module named 'numpy.array'; 'numpy' is not a package

但是,我已经在我的电脑上安装了 numpy.我该如何解决这个错误?

But, I already installed numpy in my pc. How can I solve this bug?

推荐答案

错误是由于循环导入.这意味着在当前目录(文件夹)和 np.py 中有一个名为 numpy.py 的文件,当您使用import numpy"时,它实际上是在导入 numpy.py,而不是实际的模块.为了防止这种情况,只需将 numpy.py 文件的名称更改为其他名称.切勿使用模块名称命名 python 文件.

The Error is due to Circular Import. This means that there is a file named numpy.py in the current directory(folder) and in np.py when you are using 'import numpy' it is actually importing numpy.py, not the actual module. To prevent this just change the name of numpy.py file to something else. Never name a python file with module names.

这篇关于&quot;ModuleNotFoundError: 没有名为 'numpy.array' 的模块;'numpy' 不是一个包"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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