Skip to content

Conversation

atemate-dh
Copy link

@atemate-dh atemate-dh commented Sep 3, 2025

Closes #170 and other issues

Root problem:

  • setup.py requires another package's build environment to have torch installed - or it "helps" by trying to install torch itself, which is not possible when using uv, poetry or other non-pip build systems

Minimal reproducible setup:
Step into a temp directory, create an isolated environment with uv (also works with poetry):

cd `mktemp -d`
curl -LsSf https://astral.sh/uv/install.sh | sh
uv venv
source .venv/bin/activate

Create a new project:

$ uv init test-gdino
Initialized project `test-gdino` at `/private/var/folders/6g/pv8036cd7gnb1c86vc3jhx69dh2brq/T/tmp.zLL3ozTTJj/test-gdino`
$ tree
.
└── test-gdino
    ├── main.py
    ├── pyproject.toml
    └── README.md

Add grounding dino as git-dependency:

$ cat test-gdino/pyproject.toml
[project]
name = "test-gdino"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.10"
dependencies = [
  "groundingdino @ git+https://github.com/IDEA-Research/GroundingDINO.git@856dde2"
]

Try to resolve depednencies into a requirements-lock.txt file, observe error:

uv pip compile pyproject.toml -o requirements-lock.txt
    Updated https://github.com/IDEA-Research/GroundingDINO.git (856dde20aee659246248e20734ef9ba5214f5e44)
  × Failed to build `groundingdino @ git+https://github.com/IDEA-Research/GroundingDINO.git@856dde2`
  ├─▶ The build backend returned an error
  ╰─▶ Call to `setuptools.build_meta:__legacy__.build_wheel` failed (exit status: 1)

      [stderr]
      /Users/a.yushkovskiy/.cache/uv/builds-v0/.tmpKMLQB8/bin/python: No module named pip
      Traceback (most recent call last):
        File "<string>", line 32, in install_torch
      ModuleNotFoundError: No module named 'torch'

      During handling of the above exception, another exception occurred:

      Traceback (most recent call last):
        File "<string>", line 14, in <module>
        File "/Users/a.yushkovskiy/.cache/uv/builds-v0/.tmpKMLQB8/lib/python3.10/site-packages/setuptools/build_meta.py", line 331, in get_requires_for_build_wheel
          return self._get_build_requires(config_settings, requirements=[])
        File "/Users/a.yushkovskiy/.cache/uv/builds-v0/.tmpKMLQB8/lib/python3.10/site-packages/setuptools/build_meta.py", line 301, in _get_build_requires
          self.run_setup()
        File "/Users/a.yushkovskiy/.cache/uv/builds-v0/.tmpKMLQB8/lib/python3.10/site-packages/setuptools/build_meta.py", line 512, in run_setup
          super().run_setup(setup_script=setup_script)
        File "/Users/a.yushkovskiy/.cache/uv/builds-v0/.tmpKMLQB8/lib/python3.10/site-packages/setuptools/build_meta.py", line 317, in run_setup
          exec(code, locals())
        File "<string>", line 37, in <module>
        File "<string>", line 34, in install_torch
        File "/Users/a.yushkovskiy/.pyenv/versions/3.10.10/lib/python3.10/subprocess.py", line 369, in check_call
          raise CalledProcessError(retcode, cmd)
      subprocess.CalledProcessError: Command '['/Users/a.yushkovskiy/.cache/uv/builds-v0/.tmpKMLQB8/bin/python', '-m', 'pip', 'install', 'torch']' returned non-zero exit status 1.

      hint: This usually indicates a problem with the package or the build environment.

Now, try to change dependency to current fork branch to test it:

$ cat pyproject.toml
[project]
name = "test-gdino"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.10"
dependencies = [
  "groundingdino @ git+https://github.com/atemate-dh/GroundingDINO@add-pyproject"  # <- note installing from current branch
]

Try again - success, dependencies locked! 🎉 Click below to see locked file.

uv pip compile pyproject.toml -o requirements-lock.txt
Resolved 45 packages in 874ms
# This file was autogenerated by uv via the following command:
#    uv pip compile pyproject.toml -o requirements-lock.txt
addict==2.4.0
    # via groundingdino (pyproject.toml)
certifi==2025.8.3
    # via requests
charset-normalizer==3.4.3
    # via requests
contourpy==1.3.2
    # via matplotlib
cycler==0.12.1
    # via matplotlib
defusedxml==0.7.1
    # via supervision
filelock==3.19.1
    # via
    #   huggingface-hub
    #   torch
    #   transformers
fonttools==4.59.2
    # via matplotlib
fsspec==2025.9.0
    # via
    #   huggingface-hub
    #   torch
hf-xet==1.1.9
    # via huggingface-hub
huggingface-hub==0.34.4
    # via
    #   timm
    #   tokenizers
    #   transformers
idna==3.10
    # via requests
jinja2==3.1.6
    # via torch
kiwisolver==1.4.9
    # via matplotlib
markupsafe==3.0.2
    # via jinja2
matplotlib==3.10.6
    # via supervision
mpmath==1.3.0
    # via sympy
networkx==3.4.2
    # via torch
numpy==2.2.6
    # via
    #   groundingdino (pyproject.toml)
    #   contourpy
    #   matplotlib
    #   opencv-python
    #   pycocotools
    #   scipy
    #   supervision
    #   torchvision
    #   transformers
opencv-python==4.12.0.88
    # via
    #   groundingdino (pyproject.toml)
    #   supervision
packaging==25.0
    # via
    #   huggingface-hub
    #   matplotlib
    #   transformers
pillow==11.3.0
    # via
    #   matplotlib
    #   supervision
    #   torchvision
platformdirs==4.4.0
    # via yapf
pycocotools==2.0.10
    # via groundingdino (pyproject.toml)
pyparsing==3.2.3
    # via matplotlib
python-dateutil==2.9.0.post0
    # via matplotlib
pyyaml==6.0.2
    # via
    #   huggingface-hub
    #   supervision
    #   timm
    #   transformers
regex==2025.9.1
    # via transformers
requests==2.32.5
    # via
    #   huggingface-hub
    #   supervision
    #   transformers
safetensors==0.6.2
    # via
    #   timm
    #   transformers
scipy==1.15.3
    # via supervision
six==1.17.0
    # via python-dateutil
supervision==0.26.1
    # via groundingdino (pyproject.toml)
sympy==1.14.0
    # via torch
timm==1.0.19
    # via groundingdino (pyproject.toml)
tokenizers==0.22.0
    # via transformers
tomli==2.2.1
    # via yapf
torch==2.8.0
    # via
    #   groundingdino (pyproject.toml)
    #   timm
    #   torchvision
torchvision==0.23.0
    # via
    #   groundingdino (pyproject.toml)
    #   timm
tqdm==4.67.1
    # via
    #   huggingface-hub
    #   supervision
    #   transformers
transformers==4.56.0
    # via groundingdino (pyproject.toml)
typing-extensions==4.15.0
    # via
    #   huggingface-hub
    #   torch
urllib3==2.5.0
    # via requests
yapf==0.43.0
    # via groundingdino (pyproject.toml

@atemate-dh atemate-dh changed the title Add pyproject.toml Add self-contained pyproject.toml, keep setup.py and requirements.txt untouched Sep 3, 2025
@atemate-dh atemate-dh changed the title Add self-contained pyproject.toml, keep setup.py and requirements.txt untouched Add PEP 621-compliant pyproject.toml, keep setup.py and requirements.txt untouched as legacy Sep 3, 2025
@atemate-dh
Copy link
Author

Hey @SlongLiu @rentainhe @SkalskiP - I see this repo is not maintained anymore, who's in charge of reviewing and merging PRs?

@atemate-dh atemate-dh changed the title Add PEP 621-compliant pyproject.toml, keep setup.py and requirements.txt untouched as legacy Add PEP 621-compliant pyproject.toml with locked numpy<2, keep setup.py and requirements.txt untouched as legacy Sep 3, 2025
@atemate-dh atemate-dh changed the title Add PEP 621-compliant pyproject.toml with locked numpy<2, keep setup.py and requirements.txt untouched as legacy Add PEP 621-compliant pyproject.toml, keep setup.py and requirements.txt untouched as legacy Sep 3, 2025
"addict",
"yapf",
"timm",
"numpy<2",
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

numpy<2 because torch 2.1.2 (from dockerfile) is compiled with numpy 1:

  A module that was compiled using NumPy 1.x cannot be run in
  NumPy 2.2.6 as it may crash. To support both 1.x and 2.x
  versions of NumPy, modules must be compiled with NumPy 2.0.
  Some module may need to rebuild instead e.g. with 'pybind11>=2.12'.

  If you are a user of the module, the easiest solution will be to
  downgrade to 'numpy<2' or try to upgrade the affected module.
  We expect that some modules will need time to support NumPy 2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

torch not installed as dependencies when installing groundingdino
1 participant