This may help:

https://pyinstaller.org/en/stable/hooks-config.html#matplotlib-hooks

However, I'm not sure how the MPL PDF back-end works -- it may be a special
case -- depend on ghostscript, or something else that is not pure-python,
and may not be getting included. Quick googling didn't help, but something
to keep in mind.

HTH,
  -CHB



On Mon, Aug 26, 2024 at 7:40 AM Volodymyr <[email protected]> wrote:

> Dear Pyinstaller and Matplotlib users.
>
> Found this problem with my project
>
> Matplotlib and Tkinter based application with export to PDF works great
> until you compile it to Exe file by PyInstaller. So I made simple app that
> show the problem:
>
> When execute Exe file and try to export pdf file - program drop this error
> text to console:
> ModuleNotFoundError: No module named ‘matplotlib.backends.backend_pdf’
> P.S. Importing this “matplotlib.backends.backend_pdf” module in code does
> not help
>
> My configuration:
> Python 3.11.9 x64
> Matplotlib 3.9.2
> PyInstaller 6.10.0
>
> Command to compile: pyInstaller.exe SaveToPdfApp.py --onedir --noconsole
> --noconfirm --noupx --console
>
> Simple sample code:
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> *import tkinter as tkfrom tkinter import filedialogfrom
> matplotlib.backends.backend_tkagg import FigureCanvasTkAggimport
> matplotlib.pyplot as pltimport numpy as np#from
> matplotlib.backends.backend_pdf import PdfPagesdef save_plot_as_pdf():
> file_path = filedialog.asksaveasfilename(defaultextension=".pdf",
> filetypes=[("PDF files", "*.pdf")])    if file_path:        #with
> PdfPages(file_path) as pdf:            #pdf.savefig(figure)
> figure.savefig(file_path, format="pdf")        print(f"Plot saved as
> {file_path}")root = tk.Tk()root.title("Matplotlib Plot in Tkinter")x =
> np.linspace(0, 10, 100)y = np.sin(x)figure = plt.Figure(figsize=(6, 4),
> dpi=100)ax = figure.add_subplot(111)ax.plot(x, y, label="Sine
> wave")ax.set_title("Simple Sine Wave
> Plot")ax.set_xlabel("X-axis")ax.set_ylabel("Y-axis")ax.legend()canvas =
> FigureCanvasTkAgg(figure, root)canvas.get_tk_widget().pack(side=tk.TOP,
> fill=tk.BOTH, expand=1)save_button = tk.Button(root, text="Save as PDF",
> command=save_plot_as_pdf)save_button.pack(side=tk.BOTTOM)root.mainloop()*
>
> --
> You received this message because you are subscribed to the Google Groups
> "PyInstaller" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/pyinstaller/5df5f033-dada-4b97-849e-397fce45b6e8n%40googlegroups.com
> <https://groups.google.com/d/msgid/pyinstaller/5df5f033-dada-4b97-849e-397fce45b6e8n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>


-- 

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

[email protected]

-- 
You received this message because you are subscribed to the Google Groups 
"PyInstaller" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/pyinstaller/CALGmxEJtkuG8VK_tj1XAdZ4%3DOa3EjWfmV2%2Bax_%2Btn47WyQ-fYQ%40mail.gmail.com.

Reply via email to