Skip to content

Disallow missing image libraries during setup? #7151

@pmeier

Description

@pmeier

To customize the installation, we have a few environment variables, e.g.

vision/setup.py

Lines 146 to 149 in 6a85ef2

use_png = os.getenv("TORCHVISION_USE_PNG", "1") == "1"
print(f" TORCHVISION_USE_PNG: {use_png}")
use_jpeg = os.getenv("TORCHVISION_USE_JPEG", "1") == "1"
print(f" TORCHVISION_USE_JPEG: {use_jpeg}")

As can be seen above, by default they are set to 1, which indicates that the user wants to build torchvision with PNG and JPEG support. However, we don't require the dependencies, namely libpng and libjpeg to be present:

vision/setup.py

Lines 256 to 259 in 6a85ef2

png_found = libpng is not None or pngfix is not None
use_png = use_png and png_found
if use_png:

vision/setup.py

Lines 291 to 292 in 6a85ef2

else:
print("Building torchvision without PNG image support")

Only if one of the two is present, we simply build the image extension:

vision/setup.py

Lines 332 to 335 in 6a85ef2

if use_png or use_jpeg:
ext_modules.append(
extension(
"torchvision.image",

However, if users import torchvision after successful installation, they are met with this warning:

UserWarning: Failed to load image Python extension: 

Unless they want to use the image functionality from torchvision.io, this is not an issue and #7150 is trying to fix that.

In the mean time, the behavior described above can lead to issues like #7036. Plus, there is also this really long thread in the user forum also reporting this (I'm aware that there are reports of this warning popping up from an official nightly release, but there are also people that face this after building from source).

IMO, we should discuss if we should accept that one of the image libraries is not available during build. Meaning, by default the libraries are required and the setup could simply fail if they are not found. If the user doesn't care about the I/O functionality they need to explicitly set USE_PNG=0 USE_JPEG=0 python setup.py install.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions