AttributeError: 'module' object has no attribute 'popall'

AttributeError: 'module' object has no attribute 'popall'

我运行这个命令

python tes4.py

它会导致此错误:

AttributeError: 'module' object has no attribute 'popall'

我的程序是这样的

import cv2
import numpy as np
from matplotlib import pyplot as plt

gray_img = cv2.imread('lena.jpg', cv2.IMREAD_GRAYSCALE)
cv2.imshow('GoldenGate',gray_img)
#hist = cv2.calcHist([gray_img],[0],None,[256],[0,256])
hist,bins = np.histogram(gray_img,256,[0,256])

plt.hist(gray_img.ravel(),256,[0,256])
plt.title('Histogram for gray scale picture')
plt.show()

while True:
    k = cv2.waitKey(0) & 0xFF     
    if k == 27: break             # ESC key to exit
cv2.destroyAllWindows()

我该怎么办??

np.ravel(gray_img) 不是 gray_img.ravel()。您也可以使用 gray_img.flatten(),但 flatten 会创建一个副本,因此最好使用 ravel()

https://docs.scipy.org/doc/numpy-1.10.4/reference/generated/numpy.ravel.html
https://docs.scipy.org/doc/numpy-1.10.4/reference/generated/numpy.ndarray.flatten.html