1

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

5
  • 1
    Are you using Python 3, right? Try sudo apt-get install python3-tk. Commented Apr 17, 2018 at 3:59
  • ok, I will try that. I just wanted to know if there was any workaround for same. Commented Apr 17, 2018 at 4:04
  • 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. Commented Apr 17, 2018 at 4:10
  • 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. Commented Apr 17, 2018 at 4:33
  • @aradhanasingh Use a non-interactive backend like agg. Commented Apr 17, 2018 at 9:07

2 Answers 2

1

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
Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.