Python 讯息;Matplotlib当前正在使用agg";Matplotlib没有';t显示图像

Python 讯息;Matplotlib当前正在使用agg";Matplotlib没有';t显示图像,python,matplotlib,tkinter,Python,Matplotlib,Tkinter,其他人有这个问题,我用他们的解决方案,但没有解决 我将虚拟环境与python3.5一起使用。 Matplotlib安装在virtual env下。 我在系统上安装了python3.tkinter 当我检查 matplotlib.get_backend() 我有 >>> import matplotlib >>> matplotlib.get_backend() 'TkAgg' 但是当我运行下面的代码时 for image_path in TEST_IMAG

其他人有这个问题,我用他们的解决方案,但没有解决

我将
虚拟环境与python3.5一起使用。
Matplotlib
安装在
virtual env
下。 我在系统上安装了python3.tkinter

当我检查

matplotlib.get_backend()
我有

>>> import matplotlib
>>> matplotlib.get_backend()
'TkAgg'
但是当我运行下面的代码时

for image_path in TEST_IMAGE_PATHS:
  image = Image.open(image_path)
  # the array based representation of the image will be used later in order to prepare the
  # result image with boxes and labels on it.
  image_np = load_image_into_numpy_array(image)
  # Expand dimensions since the model expects images to have shape: [1, None, None, 3]
  image_np_expanded = np.expand_dims(image_np, axis=0)
  # Actual detection.
  output_dict = run_inference_for_single_image(image_np, detection_graph)
  # Visualization of the results of a detection.
  vis_util.visualize_boxes_and_labels_on_image_array(
      image_np,
      output_dict['detection_boxes'],
      output_dict['detection_classes'],
      output_dict['detection_scores'],
      category_index,
      instance_masks=output_dict.get('detection_masks'),
      use_normalized_coordinates=True,
      line_thickness=8)
  #plt.figure(figsize=IMAGE_SIZE)
  plt.imshow(image_np)
  plt.show()
我也有问题

 UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure.
  % get_backend())
我把头球放在了后面

from io import StringIO
import matplotlib
matplotlib.rcParams["backend"] = "TkAgg"
from matplotlib import pyplot as plt
from PIL import Image
有人说它已经解决了,但我仍然有同样的问题,
plt
不显示图像。

与Matplotlib后端一样

尽管如此,上面链接的文件还表明,TkAgg应可用:

[…]Tk框架(TkAgg后端)不需要任何外部依赖项,通常总是可用的

我使用Ubuntu,我认为TkAgg将依赖PyGObject。该选项本身有一个链接到构建指令的注释

接下来,我去安装了它的系统:

sudo apt get安装-y python3-venv python3-wheel python3-dev
sudo apt get安装-y libgirepository1.0-dev build-sential\
libbz2开发libreadline开发libssl开发zlib1g开发libsqlite3开发wget\
curl llvm libncurses5开发libncursesw5开发xz utils tk开发libcairo2开发
然后将以下内容添加到我的项目的虚拟环境中:

  • 皮开罗
  • pygobject
#在我的项目的虚拟环境中
pip安装pycairo
pip安装pygobject
完成后,像往常一样运行我的项目将显示预期的图形

笔记
  • 我正在项目的虚拟环境中使用Ubuntu 18.04.2和Python 3.6.8

  • 我跳过了PyGObject的大部分构建说明,只做了上面描述的事情


在我的例子中,我通过用PIL图像函数替换pyplot函数解决了这个问题:

(我猜某些图像格式的函数出错了)


你的警告不是很清楚吗?您需要使用GUI类型的后端来获取带有
show()
的图像。你使用的是什么系统?Ubuntu 16.04。这是警告。但问题是图像没有显示。请查看中是否有任何帮助,尤其是显示如何找出哪些后端可用的部分。在许多其他例子中,演示了如何更改当前后端。如何执行程序?哪个python命令?
哪个python3
的结果是什么?如果将
matplotlib.rcParams[“backend”]=“TkAgg”
替换为
matplotlib.use(“TkAgg”)
?@pierredebyl
哪个python3
给了我
/home/cnv/venvpy3\u cpu/bin/python3
matplotlib.use(“TkAgg”)
仍然有相同的警告,没有图像显示。
import matplotlib
matplotlib.use('GTK3Agg')
import matplotlib.pyplot as plt

from PIL import Image


# plt.imshow(image_np)
# plt.show()
img = Image.fromarray(image_np, 'RGB')
img.show()