pytorch / pytorch/vision

Disallow missing image libraries during setup?

Open
#7,151 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

needs discussion topic: build
Dominant language
Python
Stars
17.9k
Forks
7.3k
Avg merge
1d 15h
Merged PRs (30d)
13

Description

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

https://github.com/pytorch/vision/blob/6a85ef24ba7a5d5879c4bd795972881ef5001c9b/setup.py#L146-L149

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:

https://github.com/pytorch/vision/blob/6a85ef24ba7a5d5879c4bd795972881ef5001c9b/setup.py#L256-L259

https://github.com/pytorch/vision/blob/6a85ef24ba7a5d5879c4bd795972881ef5001c9b/setup.py#L291-L292

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

https://github.com/pytorch/vision/blob/6a85ef24ba7a5d5879c4bd795972881ef5001c9b/setup.py#L332-L335

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with setup.py at the linked environment-variable and dependency checks around lines 146-149, 256-259, 291-292, and 332-335. Review the related issues and forum thread, then determine the agreed default behavior and verify installation with and without libpng/libjpeg, including the explicit USE_PNG=0 USE_JPEG=0 path.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
build-system, computer-vision
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.