如何修复AttributeError: module 'numpy' has no attribute 'square'错误

24

我已将numpy更新至1.14.0版本。我使用的是Windows 10操作系统。当我尝试运行我的代码时,遇到了以下错误:

AttributeError: module 'numpy' has no attribute 'square'

这是我的导入内容:

%matplotlib inline
import matplotlib.pyplot as plt
import tensorflow as tf
import numpy as np
from sklearn.metrics import confusion_matrix
import math

2
如果你将一个文件命名为 numpy.py,请选择另一个名称(如果有相应的 numpy.pyc 文件,请将其删除)。 - user2357112
展示完整的代码和完整的错误信息。 - ShpielMeister
@user2357112 我按照您说的做了,但是我现在遇到了新的错误:module 'numpy' has no attribute '__version__' - Hoda Fakharzadeh
1
当加载 matplotlib 时,我遇到了这个错误。 - mikey
1个回答

17

我删除了numpy.py文件,然后更新了numpy,它就可用了!


9
我运行了conda update --allpip uninstall -y numpypip uninstall -y setuptoolspip install setuptools==39.1.0pip install numpy,这似乎解决了关于"'numpy' has no attribute 'square'"的错误。 - Ryan
2
以上解决方案可行,除了我没有硬编码版本。卸载numpy和scipy,然后重新安装它们即可。 - Shibani

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接