在 Ubuntu 20.04 上的 Jupyter 中運行以下代碼時:
import matplotlib
try:
matplotlib.use("TkAgg")
import matplotlib.pyplot as plt
except ImportError as e:
print(e)
plt = None
assert plt is not None, "matplotlib backend failed"
print("done")
這是輸出:
Cannot load backend 'TkAgg' which requires the 'tk' interactive framework, as 'headless' is currently running
---------------------------------------------------------------------------
AssertionError Traceback (most recent call last)
/tmp/ipykernel_5612/97292621.py in <cell line: 9>()
7 plt = None
8
----> 9 assert plt is not None, "matplotlib backend failed"
10 print("done")
AssertionError:matplotlib 后端失敗
但是我可以直接從命令列運行它python3而沒有任何問題。
是否需要先匯入或安裝任何包才能在 Jupyter 筆記本中運行它python?system
uj5u.com熱心網友回復:
嘗試在空單元格上運行此命令:
%matplotlib tk
然后,執行您的繪圖命令。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/461538.html
