Repository navigation
Closed
Milestone
Description
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
Metadata
Metadata
Assignees
Labels
No labels
Activity
rcomer commentedon Jul 2, 2025
Thanks for the report. I believe this is fixed by #30221.
cacti77 commentedon Jul 2, 2025
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).
rcomer commentedon Jul 2, 2025
Probably a question for @ksunden
QuLogic commentedon Jul 2, 2025
Unlikely, as we have no plans to make another 3.9 release.
cacti77 commentedon Jul 4, 2025
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.
rcomer commentedon Jul 4, 2025
Matplotlib 3.10 requires at least python 3.10
https://matplotlib.org/stable/install/dependencies.html
cacti77 commentedon Jul 4, 2025
Thanks. So matplotlib users on Python 3.9 will just have to put up with this
DeprecationWarningthen? 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.