1

I'm trying to run the CARLA simulator but I'm constantly getting this error.

  File "module_7.py", line 32, in <module>
    import live_plotter as lv   # Custom live plotting library
  File "/opt/CarlaSimulator/PythonClient/live_plotter.py", line 7, in <module>
    import matplotlib.backends.tkagg as tkagg
ModuleNotFoundError: No module named 'matplotlib.backends.tkagg'

These are the imports in the file live_plotter.py:

import tkinter as tk
import os

import numpy as np
import matplotlib.backends.tkagg as tkagg
from matplotlib.backends.backend_agg import FigureCanvasAgg
import matplotlib.pyplot as plt
import pygame

I've tried to install matplotlib numerous times but it just doesn't work.

Onur-Andros Ozbek
  • 2,998
  • 2
  • 29
  • 78
  • Try opening your command prompt in administrator mode and first of all uninstall matplotlib and then toggle a fresh install for matplotlib –  Jun 30 '20 at 18:03
  • Do any of the answers to [this question](https://stackoverflow.com/questions/20582384/importerror-no-module-named-backend-tkagg) help? – snakecharmerb Jun 30 '20 at 18:07
  • Have you tried importing matplotlib first then `matplotlib.use('TkAgg')` – AshlinJP Jun 30 '20 at 18:50
  • @AshlinJP When I do that, I get the `NameError: name 'tkagg' is not defined` error – Onur-Andros Ozbek Jun 30 '20 at 19:27
  • And when I do `tkagg = matplotlib.use('TkAgg')`, I get this error: `tkagg.blit(photo, fca.get_renderer()._renderer, colormode=2) AttributeError: 'NoneType' object has no attribute 'blit'` – Onur-Andros Ozbek Jun 30 '20 at 19:31
  • Can you check your backend by `print(matplotlib.get_backend())`. If not TkAgg may be hardset following this https://github.com/matplotlib/matplotlib/issues/7115/#issuecomment-389369332 ? – AshlinJP Jun 30 '20 at 21:29

1 Answers1

2

Try this:

import matplotlib.backends.backend_tkagg as tkagg
from matplotlib.backends.backend_tkagg import FigureCanvasAgg

It works for me.

Apostolos
  • 3,115
  • 25
  • 28