Skip to content

Conversation

josiahls
Copy link

@josiahls josiahls commented Jul 8, 2025

This resolves a build failure when installing detectron2 with PEP 517-compliant tools such as uv or modern versions of pip.

When using build isolation (the default for these tools), installation fails with the following error:

ModuleNotFoundError: No module named 'torch'

This is because setup.py imports torch, but torch is not declared as a build requirement. As a result, it is not available in the isolated build environment.

This MR adds a pyproject.toml declaring torch under [build-system].requires, ensuring it is installed prior to running setup.py.

While installing torch manually before installing detectron2 is a workaround, that approach breaks standard installation flows (e.g., uv pip install detectron2 or uv pip install -e .) — especially in CI or production packaging pipelines.

Related upstream issue: #5117

When installing detectron2 with PEP 517-compliant tools like `uv` or `pip`, the build process fails due to `torch` not being available in the isolated build environment. This results in:

    ModuleNotFoundError: No module named 'torch'

This happens because `setup.py` imports `torch`, but torch isn't declared as a build dependency. Adding a `pyproject.toml` with `torch` listed under `[build-system].requires` ensures that torch is installed into the build environment before running `setup.py`, resolving the issue cleanly.
One solution is to have the user install torch before installing the package, but tools such as uv by default leverage build isolation.
On the developer's machine this might not be an issue, however in automated ci systems that expect standard uv installation behavior, this becomes problematic.

This fix makes the package compatible with modern Python packaging tools that enforce build isolation.
@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jul 8, 2025
@SDAChess
Copy link

Would love to see this merged as this is a major painpoint for integration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants