Damien
Damien

Reputation: 23

Nicegui, pyinstaller and matplotlib: No module named 'matplotlib.backends.backend_svg'

I want to build a onefile app with pyinstaller using the nicegui package.

Here my main.py code:

import numpy as np

from nicegui import ui

ui.label("Hello from Pyinstaller")

with ui.matplotlib(figsize=(3, 2)).figure as fig:
    x = np.linspace(0.0, 5.0)
    y = np.cos(2 * np.pi * x) * np.exp(-x)
    ax = fig.gca()
    ax.plot(x, y, "-")

ui.run(native=True, reload=False, title="PyInstaller Test")

and here the build.py I am using

import nicegui
from pathlib import Path
import subprocess
import os

static_dir = Path(nicegui.__file__).parent


cmd = [
    "py",
    "-m",
    "PyInstaller",
    "main.py",  # your main file with ui.run()
    "--name",
    "myapp",  # name of your app
    "--onefile",
    #'--windowed', # prevent console appearing, only use with ui.run(native=True, ...)
    "--add-data",
    f"{Path(nicegui.__file__).parent}{os.pathsep}nicegui",
]
subprocess.call(cmd)

Went I launch build.py I have the error: No module named 'matplotlib.backends.backend_svg'. but matplotlib is installed. When I run main.py (with ui.run()), the app works fine.

I don't have find any solution online. I also try to re-install pyinstaller, nicegui and matplotlib.

I also try import matplotlib matplotlib.use('Agg')

I don't know if I am missing something.

Upvotes: 0

Views: 227

Answers (0)

Related Questions