This question is different than matplotlib error - no module named tkinter because all of those answers are either for Linux, or Windows and I am using a Chromebook with ChromeOS. The package installer on it is called 'Chromebrew' and it doesn't have either the 'tkinter' or 'python3-tk' package.
I am having trouble installing and using matplotlib on the Bash Shell on a ChromeOS Chromebook using either 'crew' to install or 'pip3'. I have tried everything but when I try and import matplotlib I get the following error:
File "/usr/local/lib/python3.6/site-packages/matplotlib/pyplot.py", line 116, in <module>
_backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
File "/usr/local/lib/python3.6/site-packages/matplotlib/backends/__init__.py", line 60, in pylab_setup
[backend_name], 0)
File "/usr/local/lib/python3.6/site-packages/matplotlib/backends/backend_tkagg.py", line 6, in <module>
from six.moves import tkinter as Tk
File "/usr/local/lib/python3.6/site-packages/six.py", line 92, in __get__
result = self._resolve()
File "/usr/local/lib/python3.6/site-packages/six.py", line 115, in _resolve
return _import_module(self.mod)
File "/usr/local/lib/python3.6/site-packages/six.py", line 82, in _import_module
__import__(name)
File "/usr/local/lib/python3.6/tkinter/__init__.py", line 36, in <module>
import _tkinter # If this fails your Python may not be configured for Tk
ModuleNotFoundError: No module named '_tkinter'
On the terminal and I have no idea how to fix it. If anyone knows, it would be greatly appreciated.
Thanks
I found an answer, instead of trying to get the 'tkinter' to work I found a work around. If you change matplotlib backend to 'Agg' and then save the figure instead of display it seems to work. Code:
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
plt.plot([1, 2])
plt.savefig('image.jpg')
Thanks