1
votes

I am trying to plot using pyplot:
When I try to execute my script. It complains about python3-tk module not found. I understand this package needs to be installed to get this working. Is there any workaround to resolve this?

Traceback (most recent call last): File "/home/user1/PycharmProjects/programs/frequency.py", line 81, in from matplotlib import pyplot as plt File "/home/user1/PycharmProjects/programs/venv/lib/python3.5/site-packages/matplotlib/pyplot.py", line 115, in _backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup() File "/home/user1/PycharmProjects/programs/venv/lib/python3.5/site-packages/matplotlib/backends/init.py", line 62, in pylab_setup [backend_name], 0) File "/home/user1/PycharmProjects/programs/venv/lib/python3.5/site-packages/matplotlib/backends/backend_tkagg.py", line 4, in from . import tkagg # Paint image to Tk photo blitter extension. File "/home/user1/PycharmProjects/programs/venv/lib/python3.5/site-packages/matplotlib/backends/tkagg.py", line 5, in from six.moves import tkinter as Tk File "/home/user1/PycharmProjects/programs/venv/lib/python3.5/site-packages/six.py", line 92, in get result = self._resolve() File "/home/user1/PycharmProjects/programs/venv/lib/python3.5/site-packages/six.py", line 115, in _resolve return _import_module(self.mod) File "/home/user1/PycharmProjects/programs/venv/lib/python3.5/site-packages/six.py", line 82, in _import_module import(name) File "/usr/lib/python3.5/tkinter/init.py", line 38, in raise ImportError(str(msg) + ', please install the python3-tk package') ImportError: No module named '_tkinter', please install the python3-tk package

2
Are you using Python 3, right? Try sudo apt-get install python3-tk.Dalton Cézane
ok, I will try that. I just wanted to know if there was any workaround for same.aradhana singh
Really, you wanted to know if there's a workaround to having a module installed before importing it? I'm genuinely curious as to what you'd imagine said workaround to look like.Mad Physicist
No,I am not using module(python3-tk) in my script. I am just saving the figure(which i am plotting) in non-interactive mode, So I thought of asking is there a work around to avoid installing python3-tk module.aradhana singh
@aradhanasingh Use a non-interactive backend like agg.Stop harming Monica

2 Answers

0
votes

you can refer to this issue. https://github.com/ufoym/deepo/issues/17

try using this code

import matplotlib
matplotlib.use('agg')

As Dalton suggested it is best to install python3-tk.

1
votes

If you are using Python 3, try:

sudo apt-get install python3-tk

If the Python version is 3.6:

sudo apt-get install python3.6-tk

Repository needed for python3.6-tk:

sudo add-apt-repository ppa:deadsnakes/ppa