tensorboard icon indicating copy to clipboard operation
tensorboard copied to clipboard

Tensorboard fails in python 3.13 because `imghdr` module is absent

Open Bichidian opened this issue 1 year ago • 2 comments

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.

Bichidian avatar Dec 18 '24 09:12 Bichidian

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.

arcra avatar Dec 20 '24 23:12 arcra

You can install standard-imghdr for temporary fix

hzhangxyz avatar Jan 06 '25 02:01 hzhangxyz

Any news on this? If no work on this has been done, would you be open to one of the following solutions?

  1. Taking on https://github.com/h2non/filetype.py as a dependency to replace the two calls to imagehdr.what
  2. 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.

E1k3 avatar Mar 28 '25 18:03 E1k3

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.

foxik avatar Mar 28 '25 18:03 foxik

Fine by me, as long as I can use tensorboard with 3.13 without pushing standard-imghdr everywhere.

E1k3 avatar Mar 28 '25 19:03 E1k3

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 install does work anymore (for good reasons)
  • in a uv managed environment, uv will be happy to install tensorboard via uv tool install tensorboard and then add 'standard-imagehdr' via uv add standard-imagehdr to a project. Alas, then running uv run tensorboard will still fail as, for whatever reason, the library is still not found

DrMicrobit avatar Jun 23 '25 08:06 DrMicrobit

Would have loved to help, but apparently contributing is impossible without a google account.

E1k3 avatar Jun 23 '25 12:06 E1k3

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.

arcra avatar Jul 07 '25 19:07 arcra

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.

arcra avatar Jul 18 '25 01:07 arcra