Skip to content

[Bug]: DeprecationWarning from Pillow 11.3.0 about 'mode' parameter of PIL.Image.fromarray() #30249

Closed

Description

@cacti77

Bug summary

Pillow 11.3.0 has deprecated the 'mode' parameter for PIL.Image.fromarray(). The DeprecationWarning causes Azure DevOps builds using matplotlib's plt.figure() to fail when PYTHONWARNINGS=error

Code for reproduction

This stacktrace is from an Azure DevOps Microsoft-hosted Windows agent ('windows-2019' VM image) using Python 3.9.13:

Traceback (most recent call last):
<our code deleted>
    self._fig = plt.figure(figsize=(9, 6))
  File "C:\hostedtoolcache\windows\Python\3.9.13\x64\lib\site-packages\matplotlib\pyplot.py", line 1027, in figure
    manager = new_figure_manager(
  File "C:\hostedtoolcache\windows\Python\3.9.13\x64\lib\site-packages\matplotlib\pyplot.py", line 550, in new_figure_manager
    return _get_backend_mod().new_figure_manager(*args, **kwargs)
  File "C:\hostedtoolcache\windows\Python\3.9.13\x64\lib\site-packages\matplotlib\backend_bases.py", line 3507, in new_figure_manager
    return cls.new_figure_manager_given_figure(num, fig)
  File "C:\hostedtoolcache\windows\Python\3.9.13\x64\lib\site-packages\matplotlib\backend_bases.py", line 3512, in new_figure_manager_given_figure
    return cls.FigureCanvas.new_manager(figure, num)
  File "C:\hostedtoolcache\windows\Python\3.9.13\x64\lib\site-packages\matplotlib\backend_bases.py", line 1797, in new_manager
    return cls.manager_class.create_with_canvas(cls, figure, num)
  File "C:\hostedtoolcache\windows\Python\3.9.13\x64\lib\site-packages\matplotlib\backends\_backend_tk.py", line 504, in create_with_canvas
    manager = cls(canvas, num, window)
  File "C:\hostedtoolcache\windows\Python\3.9.13\x64\lib\site-packages\matplotlib\backends\_backend_tk.py", line 457, in __init__
    super().__init__(canvas, num)
  File "C:\hostedtoolcache\windows\Python\3.9.13\x64\lib\site-packages\matplotlib\backend_bases.py", line 2665, in __init__
    tools.add_tools_to_container(self.toolbar)
  File "C:\hostedtoolcache\windows\Python\3.9.13\x64\lib\site-packages\matplotlib\backend_tools.py", line 1007, in add_tools_to_container
    container.add_tool(tool, group, position)
  File "C:\hostedtoolcache\windows\Python\3.9.13\x64\lib\site-packages\matplotlib\backend_bases.py", line 3323, in add_tool
    self.add_toolitem(tool.name, group, position,
  File "C:\hostedtoolcache\windows\Python\3.9.13\x64\lib\site-packages\matplotlib\backends\_backend_tk.py", line 980, in add_toolitem
    button = NavigationToolbar2Tk._Button(frame, name, image_file, toggle,
  File "C:\hostedtoolcache\windows\Python\3.9.13\x64\lib\site-packages\matplotlib\backends\_backend_tk.py", line 825, in _Button
    NavigationToolbar2Tk._set_image_for_button(self, b)
  File "C:\hostedtoolcache\windows\Python\3.9.13\x64\lib\site-packages\matplotlib\backends\_backend_tk.py", line 767, in _set_image_for_button
    im_alt = _recolor_icon(im, foreground)
  File "C:\hostedtoolcache\windows\Python\3.9.13\x64\lib\site-packages\matplotlib\backends\_backend_tk.py", line 754, in _recolor_icon
    return Image.fromarray(image_data, mode="RGBA")
  File "C:\hostedtoolcache\windows\Python\3.9.13\x64\lib\site-packages\PIL\Image.py", line 3314, in fromarray
    deprecate("'mode' parameter", 13)
  File "C:\hostedtoolcache\windows\Python\3.9.13\x64\lib\site-packages\PIL\_deprecate.py", line 68, in deprecate
    warnings.warn(
DeprecationWarning: 'mode' parameter is deprecated and will be removed in Pillow 13 (2026-10-15)

Similar failures occur in Linux and Windows on Pythons 3.9 and 3.12.

Actual outcome

DeprecationWarning: 'mode' parameter is deprecated and will be removed in Pillow 13 (2026-10-15)

Expected outcome

No deprecation warning.

Additional information

Our DevOps pipelines started breaking with this on 2 July when pillow (installed via pip) upgraded from 11.2.1 to 11.3.0.

Operating system

Windows

Matplotlib Version

3.9.4

Matplotlib Backend

Not sure, TkAgg?

Python version

3.9.13

Jupyter version

N/A

Installation

pip

Activity

  1. rcomer commented on Jul 2, 2025

    @rcomer
    Member

    Thanks for the report. I believe this is fixed by #30221.

  2. added this to the v3.10.4 milestone on Jul 2, 2025
  3. cacti77 commented on Jul 2, 2025

    @cacti77
    Author

    Thanks @rcomer - will that fix go into matplotlib 3.9.x as well? (I can confirm we're currently using 3.10.3 in our Python 3.12 Win and Linux builds).

  4. rcomer commented on Jul 2, 2025

    @rcomer
    Member

    will that fix go into matplotlib 3.9.x as well?

    Probably a question for @ksunden

  5. QuLogic commented on Jul 2, 2025

    @QuLogic
    Member

    Unlikely, as we have no plans to make another 3.9 release.

  6. cacti77 commented on Jul 4, 2025

    @cacti77
    Author

    Unlikely, as we have no plans to make another 3.9 release.

    Hmm, ok. What's the minimum Python version that's supported by matplotlib 3.10 then pls? I ask because matplotlib 3.9.4 is currently being installed by pip for the Python 3.9 jobs in our Azure DevOps build pipelines. We have no explicit version restriction on matplotlib in our requirements file.

  7. rcomer commented on Jul 4, 2025

    @rcomer
    Member

    Matplotlib 3.10 requires at least python 3.10
    https://matplotlib.org/stable/install/dependencies.html

  8. cacti77 commented on Jul 4, 2025

    @cacti77
    Author

    Thanks. So matplotlib users on Python 3.9 will just have to put up with this DeprecationWarning then? I know Python 3.9 is expected to end its life in October this year though.

    I guess I can keep the pillow < 11.3 restriction just for testing on Python 3.9, or filter the warning out, so I guess that's ok if you don't want to backport the fix to matplotlib 3.9.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions