torchvision.io: don't warn about missing image libraries unless necessary
🐛 Describe the bug
If no image libraries are installed, the following will warn:
>>> import torchvision
UserWarning: Failed to load image Python extension:
I propose we only warn when importing torchvision.io or when using a specific function that requires one of these image libraries.
Related to #7151
Versions
Collecting environment information...
Traceback (most recent call last):
File "/Users/Adam/Downloads/collect_env.py", line 624, in <module>
main()
File "/Users/Adam/Downloads/collect_env.py", line 607, in main
output = get_pretty_env_info()
^^^^^^^^^^^^^^^^^^^^^
File "/Users/Adam/Downloads/collect_env.py", line 602, in get_pretty_env_info
return pretty_str(get_env_info())
^^^^^^^^^^^^^^
File "/Users/Adam/Downloads/collect_env.py", line 438, in get_env_info
pip_version, pip_list_output = get_pip_packages(run_lambda)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/Adam/Downloads/collect_env.py", line 410, in get_pip_packages
out = run_with_pip([sys.executable, '-mpip'])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/Adam/Downloads/collect_env.py", line 405, in run_with_pip
for line in out.splitlines()
^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'splitlines'
Hi @NicolasHug, I would like to work on this issue if it is for beginners. Can you suggest me how may I proceed? Thanks
I recently re-worked our extension compilation logic and the image.so extension is now always built, unconditionally. It doesn't depend anymore on the existence of libjpeg or libpng (because we vendor libgif, which is always present, so we always build).
Because of this recent change, I'm having a hard time imagining a scenario where this warning is emitted and undesirable. @adamjstewart can you remind me exact the scenario where you got this warning? Was it when building from source in specific conditions? When installing the stable version?
It was when building from source, stable releases, but no libjpeg/libpng installed on the OS.
Thanks for confirming. I understand why this was causing an undesirable warning in the past. Now that we always build image.so, I suspect this might have become a non-issue, i.e. the extension should be available and load just fine without a warning (and only contain the gif decoder).
I'm fine with closing this if you want, although I'm also hoping for an option to build with external giflib and disable that in the future.
Do you mean to dynamically link against giflib instead of statically? If so, why is that the case?
(also let me know about https://github.com/pytorch/vision/pull/8406#discussion_r1691444762 please :) )
Replied to that thread, I mean building with a non-vendored copy of giflib.