title: Matplotlib not working for LInux. Cannot load backend 'TkAgg'
body: <p>Trying to use Matplotlib on Linux, but I keep getting this error:</p>
  
  <pre><code>ImportError: Cannot load backend 'TkAgg' which requires the 'tk' interactive framework, as 'headless' is currently running
  </code></pre>
  
  <p>I am using a virtual environment on OS: Linux 18.04 LTS. Python version: 3.6</p>
  
  <p>I have tried many solutions other posts have suggested:</p>
  
  <pre><code>sudo apt-get install tk-dev libpng-dev libffi-dev dvipng texlive-latex-base
  pip uninstall matplotlib
  pip --no-cache-dir install matplotlib
  </code></pre>
  
  <p>I have tried fiddling with the python script where matplotlib is used:</p>
  
  <pre><code>#TOP OF FILE
  import matplotlib
  matplotlib.use('Agg') # or 'TkAgg', or removing the line altogether
  import matplotlib.pyplot as plt
  ...
  </code></pre>
  
  <p>Running python to see what backend is being used:</p>
  
  <pre><code>import matplotlib
  matplotlib.get_backend()   # -&gt; 'agg'
  </code></pre>
  
  <p>Any ideas? Thank you</p>