-
Notifications
You must be signed in to change notification settings - Fork 7.1k
Description
To customize the installation, we have a few environment variables, e.g.
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:
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: |
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:
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
.