Tensorboard fails in python 3.13 because `imghdr` module is absent
Running tensorboard --logdir . under python 3.13 leads to the following error:
Traceback (most recent call last):
File ".venv/bin/tensorboard", line 5, in <module>
from tensorboard.main import run_main
File ".venv/lib64/python3.13/site-packages/tensorboard/main.py", line 27, in <module>
from tensorboard import default
File ".venv/lib64/python3.13/site-packages/tensorboard/default.py", line 40, in <module>
from tensorboard.plugins.image import images_plugin
File ".venv/lib64/python3.13/site-packages/tensorboard/plugins/image/images_plugin.py", line 18, in <module>
import imghdr
ModuleNotFoundError: No module named 'imghdr'
It seems that imghdr is no longer part of the Python standard library in 3.13.
Thanks for reporting. We'll look for a replacement for this library.
AFAICT, we only use it to get MIME types, which I expect should be somewhat easily replaceable, but we can't guarantee when we'll address this. In the meantime, Python < 3.13 would be required.
You can install standard-imghdr for temporary fix
Any news on this? If no work on this has been done, would you be open to one of the following solutions?
- Taking on https://github.com/h2non/filetype.py as a dependency to replace the two calls to imagehdr.what
- Copying the bmp, gif, jpeg and png matchers from filetype.py (MIT licensed so should be fine) to replace the two calls to imagehdr.what
If one of these is fine, I can submit a PR.
Given that the imghdr.py from the standard library has <4kB and has only trivial dependencies (os, warnings), I would just add a copy to the TensorBoard codebase? The code is simple, I would expect zero maintenance cost.
Fine by me, as long as I can use tensorboard with 3.13 without pushing standard-imghdr everywhere.
I'd like to bump this issue. Reason: the easy workarounds all are not easy anymore and Python 3.13 is quickly taking over.
- on Ubuntu 24 LTS,
pip installdoes work anymore (for good reasons) - in a
uvmanaged environment, uv will be happy to install tensorboard viauv tool install tensorboardand then add 'standard-imagehdr' viauv add standard-imagehdrto a project. Alas, then runninguv run tensorboardwill still fail as, for whatever reason, the library is still not found
Would have loved to help, but apparently contributing is impossible without a google account.
Quick update:
Last week I prepared PR #7009 as suggested by @Zamanhuseyinli in #7008, but I need to do a few things to ensure it works well with our internal repo. Last week was a short work week in the US, so I didn't have time to complete this work. I'll try to finish it this week.
However, I learned we need to do a bit more work after this to make TB work with python 3.12+. I filed #7010 to track this.
Hey folks! Today I published the release 2.20.0, which includes the chances from above. This version should be compatible with python 3.13, but please let me know if you still find any issues with this.