$ pip3 install matplotlib
Requirement already satisfied: matplotlib in /home/vorac/.local/lib/python3.7/site-packages (3.0.3)
Requirement already satisfied: cycler>=0.10 in /home/vorac/.local/lib/python3.7/site-packages (from matplotlib) (0.10.0)
Requirement already satisfied: python-dateutil>=2.1 in /home/vorac/.local/lib/python3.7/site-packages (from matplotlib) (2.8.0)
Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 in /home/vorac/.local/lib/python3.7/site-packages (from matplotlib) (2.3.0)
Requirement already satisfied: numpy>=1.10.0 in /home/vorac/.local/lib/python3.7/site-packages (from matplotlib) (1.16.3)
Requirement already satisfied: kiwisolver>=1.0.1 in /home/vorac/.local/lib/python3.7/site-packages (from matplotlib) (1.1.0)
Requirement already satisfied: six in /usr/lib/python3/dist-packages (from cycler>=0.10->matplotlib) (1.12.0)
Requirement already satisfied: setuptools in /usr/lib/python3/dist-packages (from kiwisolver>=1.0.1->matplotlib) (40.8.0)

All good. Now:

$ python3
Python 3.7.3rc1 (default, Mar 13 2019, 11:01:15) 
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib
>>> import matplotlib.pyplot as plt
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/vorac/.local/lib/python3.7/site-packages/matplotlib/pyplot.py", line 2372, in <module>
  File "/home/vorac/.local/lib/python3.7/site-packages/matplotlib/pyplot.py", line 207, in switch_backend
    backend_mod = importlib.import_module(backend_name)
  File "/usr/lib/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "/home/vorac/.local/lib/python3.7/site-packages/matplotlib/backends/backend_tkagg.py", line 1, in <module>
    from . import _backend_tk
  File "/home/vorac/.local/lib/python3.7/site-packages/matplotlib/backends/_backend_tk.py", line 5, in <module>
    import tkinter as Tk
ModuleNotFoundError: No module named 'tkinter'


$ pip3 install tkinter
Collecting tkinter
Could not install packages due to an EnvironmentError: 404 Client Error: Not Found for url: https://pypi.org/simple/tkinter/

Said page really contains just the text "404 Not Found". What am I to do in this situation. I am trying to install packages to my local $HOME, but a system-wide installation could also work.


Since you’re using Debian, and the modules you’re interested in are available as packages, we can use those to solve your problem. In circumstances such as these, where using part of a module requires another module which isn’t part of the first’s strict dependencies, there’s probably an optional dependency which would fix your problem; the package for matplotlib is python3-matplotlib, so

apt show python3-matplotlib

will tell us what optional dependencies are recommended or suggested for this module. In this case, python3-tk is listed and seems a likely candidate, which is confirmed by

apt show python3-tk


sudo apt install python3-tk

should fix your problem.

  • Such a simple solution. But how did you guess the modules are installed using packages? 6 out of 8 packages are in my $HOME, among which numpy? Also I wouldn't mind a link to an article which packages should be system-wide and which personal (excluding virtualenvs). – Vorac May 8 at 8:50
  • 1
    Oops, the first part made no sense, I’ve rewritten it. As far as best practices go, there are arguments for and against both approaches, and proponents of both; I prefer using packages but that’s just me. In this particular instance installing python3-tk was simpler than figuring out which PyPI module was necessary... (If there is one at all, tkinter is a stdlib extension.) – Stephen Kitt May 8 at 8:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.