msys2 / MINGW-packages

Package scripts for MinGW-w64 targets to build under MSYS2.
https://packages.msys2.org
BSD 3-Clause "New" or "Revised" License
2.27k stars 1.21k forks source link

Python scripts based on matplotlib do not work anymore #19540

Open angelog0 opened 10 months ago

angelog0 commented 10 months ago

My scripts based on matplotlib do not work anymore. For example the following code

import matplotlib.pyplot as plt

x = 0.74
y = 3.5

plt.plot([1,2,3,4])

plt.plot(x,y,marker='o',color='red')

plt.show()

now produces these errors:

$ python3 pltdemo.py
Traceback (most recent call last):
  File "C:/msys64/home/utente/py.apps/pltdemo.py", line 22, in <module>
    plt.plot([1,2,3,4])
  File "C:/msys64/mingw64/lib/python3.11/site-packages/matplotlib/pyplot.py", line 3578, in plot
    return gca().plot(
           ^^^^^
  File "C:/msys64/mingw64/lib/python3.11/site-packages/matplotlib/pyplot.py", line 2528, in gca
    return gcf().gca()
           ^^^^^
  File "C:/msys64/mingw64/lib/python3.11/site-packages/matplotlib/pyplot.py", line 1000, in gcf
    return figure()
           ^^^^^^^^
  File "C:/msys64/mingw64/lib/python3.11/site-packages/matplotlib/pyplot.py", line 934, in figure
    manager = new_figure_manager(
              ^^^^^^^^^^^^^^^^^^^
  File "C:/msys64/mingw64/lib/python3.11/site-packages/matplotlib/pyplot.py", line 464, in new_figure_manager
    _warn_if_gui_out_of_main_thread()
  File "C:/msys64/mingw64/lib/python3.11/site-packages/matplotlib/pyplot.py", line 441, in _warn_if_gui_out_of_main_thread
    canvas_class = cast(type[FigureCanvasBase], _get_backend_mod().FigureCanvas)
                                                ^^^^^^^^^^^^^^^^^^
  File "C:/msys64/mingw64/lib/python3.11/site-packages/matplotlib/pyplot.py", line 280, in _get_backend_mod
    switch_backend(rcParams._get("backend"))  # type: ignore[attr-defined]
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:/msys64/mingw64/lib/python3.11/site-packages/matplotlib/pyplot.py", line 327, in switch_backend
    switch_backend(candidate)
  File "C:/msys64/mingw64/lib/python3.11/site-packages/matplotlib/pyplot.py", line 342, in switch_backend
    module = importlib.import_module(cbook._backend_module_name(newbackend))
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:/msys64/mingw64/lib/python3.11/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1204, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 944, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "C:/msys64/mingw64/lib/python3.11/site-packages/matplotlib/backends/backend_gtk4agg.py", line 4, in <module>
    from . import backend_agg, backend_gtk4
  File "C:/msys64/mingw64/lib/python3.11/site-packages/matplotlib/backends/backend_gtk4.py", line 19, in <module>
    gi.require_version("Gtk", "4.0")
    ^^^^^^^^^^^^^^^^^^
AttributeError: module 'gi' has no attribute 'require_version'

The same code works in WSL and it was working until a few months ago on MSYS2/MINGW64

Windows Version

MINGW64_NT-10.0-19045

MINGW environments affected

Are you willing to submit a PR?

No response

Biswa96 commented 10 months ago

I can not reproduce the issue in my system. I have installed python-matplotlib in clean mingw64 environment and your given python script shows a diagonal plot with a red dot.

angelog0 commented 10 months ago

@Biswa96, you do not say on which OS...

Biswa96 commented 10 months ago

I am using Microsoft Windows Version 10.0.19045.xxxx

angelog0 commented 10 months ago

Maybe I have found the culprit. It is the installation of the GIMP package (both in MINGW64 and UCRT64) which breaks things. After uninstalling it with pacman -Rscn ... , things start to work again.

I wonder if this is caused by the fact that installing GIMP installs pyton2, gtk2 etc..

angelog0 commented 10 months ago

It seems that installing GIMP3 works better...

Biswa96 commented 10 months ago

So, nothing to solve, right?

angelog0 commented 10 months ago

The GIMP package conflicts with Python3. GIMP3 fixes things.

Maybe you should rename

MehdiChinoune commented 10 months ago

The GIMP package conflicts with Python3. GIMP3 fixes things.

Maybe you should rename

  • GIMP --> GIMP2 and declare it in conflict with PYTHON3 (who installs PYTHON3 cannot install GIMP2 and viceversa)
  • GIMP3 --> GIMP

We couldn't because gimp3 is not stable (officially) yet, wait until stable release.