Run this code on CentOS.
test.py
import matplotlib.pyplot as plt
plt.plot([1,2,3])
plt.show()
Then I get this error.
$ python3 test.py
test.py:3: UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure.
plt.show()
Install tkinter.
sudo yum install python3-tkinter
Then, after that, the graph is displayed properly.
$ python3 test.py
By default, Python 3 on CentOS only includes non-GUI Agg. If you include tkinter, the GUI-backend TkAgg
will be enabled and you will be able to use it.
By the way, depending on the article
import matplotlib
matplotlib.use('TkAgg')
It is written that it is necessary to explicitly specify TkAgg
like, but in my environment (CentOS Linux release 7.8.2003), just insert python3-tkinter
(X is valid) It seems that it will be used automatically.
Recommended Posts