Python 在源代码中,我输入了它,得到:UserWarning:Matplotlib当前正在使用agg,这是一个非GUI后端,因此无法显示该图

Python 在源代码中,我输入了它,得到:UserWarning:Matplotlib当前正在使用agg,这是一个非GUI后端,因此无法显示该图,python,matplotlib,Python,Matplotlib,代码是 import numpy as np import matplotlib.pyplot as plt import sys image = cv2.imread(sys.argv[1]) gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) plt.imshow(gray, cmap="gray") plt.show() edges = cv2.Canny(gray, threshold1=30, threshol

代码是

import numpy as np
import matplotlib.pyplot as plt
import sys

image = cv2.imread(sys.argv[1])


gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)


plt.imshow(gray, cmap="gray")
plt.show()


edges = cv2.Canny(gray, threshold1=30, threshold2=100)


plt.imshow(edges, cmap="gray")
plt.show()
当我按照此处链接的教程中的说明键入时,它不起作用并显示上面的消息。 完整的信息是

UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure.
  plt.show()

任何帮助都将不胜感激。谢谢大家!

如果你像ubuntu一样使用linux,需要从终端安装thinker

sudo-apt-get-install-python3-tk
在mac上

xcode-select --install
brew uninstall python
brew install python --with-tcl-tk

如果我使用windows怎么办?