Search code examples
pythonpython-3.xmatplotlibpyinstaller

ModuleNotFoundError: No module named 'matplotlib.backends.backend_svg' when running exe from pyinstaller


I want to compile a python file to a standalone .exe programm using pyinstaller onefile. Running the python file, everything works fine, but running the .exe file, it throws the exception

ModuleNotFoundError: No module named 'matplotlib.backends.backend_svg'

I am using schemdraw, and schemdraw uses matplotlib.

Because I dont want matplotlib to open a window everytime I export an svg I use the backend "Agg" with matplotlib.

import matplotlib.backends.backend_tkagg
import matplotlib
matplotlib.use('Agg')

  • I of course have tried reinstalling matplotlib
  • Using instead of pyinstaller --onefile <file> pyinstaller <file>
  • I tried putting import matplotlib.backends.backend_tkagg over import matplotlip
  • upgrading matplotlib pip install matplotlib --upgrade --user basicly this post. But since this isn't exactly my problem and none of it worked I am asking here

Thanks in advance


Solution

  • Do you need to use Matplotlib for anything other than schemdraw? If not, you can set schemdraw to draw straight to SVG:

    schemdraw.use('svg')
    

    then it won't even go through Matplotlib.