1

EDIT

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

Community
  • 1
  • 1
phlie
  • 1,335
  • 3
  • 10
  • 19
  • did you see [this question](https://stackoverflow.com/questions/36327134/matplotlib-error-no-module-named-tkinter)? I just copied your error into the search bar. or [this one](https://github.com/matplotlib/matplotlib/issues/9017) from their github? – MattR Feb 15 '18 at 21:12
  • Have you looked at this solution? https://stackoverflow.com/questions/36327134/matplotlib-error-no-module-named-tkinter – smaug Feb 15 '18 at 21:12
  • Thanks, I didn't see either, I'll try them out real quick. – phlie Feb 15 '18 at 21:13
  • 1
    Possible duplicate of [matplotlib error - no module named tkinter](https://stackoverflow.com/questions/36327134/matplotlib-error-no-module-named-tkinter) – MattR Feb 15 '18 at 21:14
  • Since it is Chromeos, there is no 'apt-get' and I have to make due with 'crew' instead, I can't find the package 'tkinter' or the package 'python3-tk'. I'll keep looking and can't seem to find them with 'pip3' either. – phlie Feb 15 '18 at 21:17
  • 1
    I found 'matplotlib.use('agg')' which you can specify different backends but don't know which one works on ChromeOS. – phlie Feb 15 '18 at 21:24
  • I assume that since a traditional Unix/Linux graphical toolkit like tkinter requires X11 or Wayland, and a chromebook doesn't provide that, they just left it out in chromebrew. But you could look more closely at the way they build Python there: https://github.com/skycocker/chromebrew/blob/master/packages/python3.rb But I'm not sure why they included `idle` then, since it requires tkinter – nealmcb Jun 26 '19 at 01:56

1 Answers1

2

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

phlie
  • 1,335
  • 3
  • 10
  • 19
  • I found [this question](https://stackoverflow.com/questions/8827016/matplotlib-savefig-in-jpeg-format). – phlie Feb 16 '18 at 00:00