You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
After upgrading from Python 3.9 to Python 3.13.0 on Windows x64 platform working python app that uses matplotlib is unable to save PNG images. Issue is related to Pillow it seems.
Traceback (most recent call last):
File "C:\Python313\Lib\site-packages\PIL\ImageFile.py", line 554, in _save
fh = fp.fileno()
^^^^^^^^^
AttributeError: '_idat' object has no attribute 'fileno'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Python313\Lib\site-packages\PIL\Image.py", line 2596, in save
save_handler(self, fp, filename)
~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^
File "C:\Python313\Lib\site-packages\PIL\PngImagePlugin.py", line 1488, in _save
ImageFile._save(
~~~~~~~~~~~~~~~^
single_im,
^^^^^^^^^^
cast(IO[bytes], _idat(fp, chunk)),
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[ImageFile._Tile("zip", (0, 0) + single_im.size, 0, rawmode)],
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File "C:\Python313\Lib\site-packages\PIL\ImageFile.py", line 558, in _save
_encode_tile(im, fp, tile, bufsize, None, exc)
~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Python313\Lib\site-packages\PIL\ImageFile.py", line 585, in _encode_tile
fp.write(data)
~~~~~~~~^^^^^^
File "C:\Python313\Lib\site-packages\PIL\PngImagePlugin.py", line 1132, in write
self.chunk(self.fp, b"IDAT", data)
~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Python313\Lib\site-packages\PIL\PngImagePlugin.py", line 1119, in putchunk
fp.write(byte_data)
~~~~~~~~^^^^^^^^^^^
OSError: [Errno 9] Bad file descriptor
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "c:\_repo\tckit\tckit_qvr.py", line 767, in <module>
fig.savefig(png_fn_small, facecolor=fig.get_facecolor(), transparent=False)
~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Python313\Lib\site-packages\matplotlib\figure.py", line 3490, in savefig
self.canvas.print_figure(fname, **kwargs)
~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
File "C:\Python313\Lib\site-packages\matplotlib\backend_bases.py", line 2184, in print_figure
result = print_method(
filename,
...<3 lines>...
bbox_inches_restore=_bbox_inches_restore,
**kwargs)
File "C:\Python313\Lib\site-packages\matplotlib\backend_bases.py", line 2040, in <lambda>
print_method = functools.wraps(meth)(lambda *args, **kwargs: meth(
~~~~^
*args, **{k: v for k, v in kwargs.items() if k not in skip}))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Python313\Lib\site-packages\matplotlib\backends\backend_agg.py", line 481, in print_png
self._print_pil(filename_or_obj, "png", pil_kwargs, metadata)
~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Python313\Lib\site-packages\matplotlib\backends\backend_agg.py", line 430, in _print_pil
mpl.image.imsave(
~~~~~~~~~~~~~~~~^
filename_or_obj, self.buffer_rgba(), format=fmt, origin="upper",
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
dpi=self.figure.dpi, metadata=metadata, pil_kwargs=pil_kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Python313\Lib\site-packages\matplotlib\image.py", line 1634, in imsave
image.save(fname, **pil_kwargs)
~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^
File "C:\Python313\Lib\site-packages\PIL\Image.py", line 2599, in save
fp.close()
~~~~~~~~^^
OSError: [Errno 9] Bad file descriptor
Expected outcome
Older Python 3.9 renders and saves PNG image normally without any issues, using same code.
Bug summary
After upgrading from Python 3.9 to Python 3.13.0 on Windows x64 platform working python app that uses matplotlib is unable to save PNG images. Issue is related to Pillow it seems.
Code for reproduction
Actual outcome
Crash log:
Expected outcome
Older Python 3.9 renders and saves PNG image normally without any issues, using same code.
Additional information
My test environment, installed using latest pip.
Operating system
Windows 10
Matplotlib Version
3.10.0
Matplotlib Backend
tkagg
Python version
3.13.0
Jupyter version
No response
Installation
pip
The text was updated successfully, but these errors were encountered: