亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

消息“Matplotlib 當前正在使用 agg”并且 Matplotlib 不顯示圖像

消息“Matplotlib 當前正在使用 agg”并且 Matplotlib 不顯示圖像

LEATH 2021-11-02 16:08:40
其他人有這個問題,我用了他們的解決方案但沒有解決。我用virtual env with 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 StringIOimport matplotlibmatplotlib.rcParams["backend"] = "TkAgg"from matplotlib import pyplot as pltfrom PIL import Image有人說已經解決了,但我還是有同樣的問題,plt不顯示圖像。
查看完整描述

2 回答

?
Helenr

TA貢獻1780條經驗 獲得超4個贊

正如您所指出的,Matplotlib 后端有時需要額外的步驟才能在虛擬環境中運行。


話雖如此,上面鏈接的文檔也表明 TkAgg 應該可用:


[...] Tk 框架(TkAgg 后端)不需要任何外部依賴項,并且通常始終可用。


我使用 Ubuntu,并且我認為 TkAgg 將依賴于 PyGObject。該選項本身有一個注釋,鏈接到構建說明。


按照PyGObject 構建說明,我去安裝它的系統依賴項:


sudo apt-get install -y python3-venv python3-wheel python3-dev

sudo apt-get install -y libgirepository1.0-dev build-essential \

  libbz2-dev libreadline-dev libssl-dev zlib1g-dev libsqlite3-dev wget \

  curl llvm libncurses5-dev libncursesw5-dev xz-utils tk-dev libcairo2-dev

然后將以下Python 依賴項添加到我項目的虛擬環境中:


皮開羅

pygobject

# inside my project's virtual environment

pip install pycairo

pip install pygobject

完成后,像往常一樣運行我的項目會顯示預期的圖形。


筆記

我在項目的虛擬環境中使用 Ubuntu 18.04.2 和 Python 3.6.8。


我跳過了 PyGObject 的大部分構建指令,只做了我上面描述的。


查看完整回答
反對 回復 2021-11-02
  • 2 回答
  • 0 關注
  • 264 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號