IDEA-Research / Grounded-Segment-Anything

Grounded SAM: Marrying Grounding DINO with Segment Anything & Stable Diffusion & Recognize Anything - Automatically Detect , Segment and Generate Anything
https://arxiv.org/abs/2401.14159
Apache License 2.0
15.16k stars 1.4k forks source link

GroundingDINO installing fails #358

Closed M-Colley closed 1 year ago

M-Colley commented 1 year ago

I have done the following


cd Grounded-Segment-Anything

pip install -r requirements.txt

cd GroundingDINO
pip install .

This is the error:

  Getting requirements to build wheel ... error
  error: subprocess-exited-with-error

  × Getting requirements to build wheel did not run successfully.
  │ exit code: 1
  ╰─> [21 lines of output]
      Traceback (most recent call last):
        File "C:\Users\miuni\AppData\Local\Programs\Python\Python311\Lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 353, in <module>
          main()
        File "C:\Users\miuni\AppData\Local\Programs\Python\Python311\Lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 335, in main
          json_out['return_val'] = hook(**hook_input['kwargs'])
                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "C:\Users\miuni\AppData\Local\Programs\Python\Python311\Lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 118, in get_requires_for_build_wheel
          return hook(config_settings)
                 ^^^^^^^^^^^^^^^^^^^^^
        File "C:\Users\miuni\AppData\Local\Temp\pip-build-env-t3uezmsd\overlay\Lib\site-packages\setuptools\build_meta.py", line 341, in get_requires_for_build_wheel
          return self._get_build_requires(config_settings, requirements=['wheel'])
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "C:\Users\miuni\AppData\Local\Temp\pip-build-env-t3uezmsd\overlay\Lib\site-packages\setuptools\build_meta.py", line 323, in _get_build_requires
          self.run_setup()
        File "C:\Users\miuni\AppData\Local\Temp\pip-build-env-t3uezmsd\overlay\Lib\site-packages\setuptools\build_meta.py", line 488, in run_setup
          self).run_setup(setup_script=setup_script)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "C:\Users\miuni\AppData\Local\Temp\pip-build-env-t3uezmsd\overlay\Lib\site-packages\setuptools\build_meta.py", line 338, in run_setup
          exec(code, locals())
        File "<string>", line 27, in <module>
      ModuleNotFoundError: No module named 'torch'
      [end of output]

pip show torch shows that torch is installed:

pip show torch Name: torch Version: 2.0.1+cu118

the environment variable CUDA_HOME is also set.

Any ideas where this comes from?

Kind regards

rentainhe commented 1 year ago

Hello, you can try:

python -m pip install -e GroundingDINO

instead of :

cd GroundingDINO
pip install .
M-Colley commented 1 year ago

Hello and thank you for the quick answer, unfortunately, this did not resolve the issue. I still get the same error.

Kind regards

rentainhe commented 1 year ago

I'm not sure why this happened, you can double check if your Torch environment is installed correctly

M-Colley commented 1 year ago

I am not entirely sure why it worked in the end, however, installing the Visual Studio Build Tools and the running

python -m pip install -e GroundingDINO

worked. Thank you.

SaulBatman commented 1 year ago

I also encountered this error on an Ubuntu machine. I solved it with "sudo apt-get install build-essential".

nikste commented 1 year ago

I get the same error with linux (build-essential are installed, torch as well). I'm working from a virtual environment (venv), might it have something to do with that?

Obtaining file:///home/nikste/grounded_sam/GroundingDINO
  Installing build dependencies ... done
  Checking if build backend supports build_editable ... done
  Getting requirements to build editable ... error
  error: subprocess-exited-with-error

  × Getting requirements to build editable did not run successfully.
  │ exit code: 1
  ╰─> [19 lines of output]
      Traceback (most recent call last):
        File "/home/nikste/grounded_sam/venv/lib/python3.10/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 353, in <module>
          main()
        File "/home/nikste/grounded_sam/venv/lib/python3.10/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 335, in main
          json_out['return_val'] = hook(**hook_input['kwargs'])
        File "/home/nikste/grounded_sam/venv/lib/python3.10/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 132, in get_requires_for_build_editable
          return hook(config_settings)
        File "/tmp/pip-build-env-arpnm8ng/overlay/lib/python3.10/site-packages/setuptools/build_meta.py", line 468, in get_requires_for_build_editable
          return self.get_requires_for_build_wheel(config_settings)
        File "/tmp/pip-build-env-arpnm8ng/overlay/lib/python3.10/site-packages/setuptools/build_meta.py", line 355, in get_requires_for_build_wheel
          return self._get_build_requires(config_settings, requirements=['wheel'])
        File "/tmp/pip-build-env-arpnm8ng/overlay/lib/python3.10/site-packages/setuptools/build_meta.py", line 325, in _get_build_requires
          self.run_setup()
        File "/tmp/pip-build-env-arpnm8ng/overlay/lib/python3.10/site-packages/setuptools/build_meta.py", line 507, in run_setup
          super(_BuildMetaLegacyBackend, self).run_setup(setup_script=setup_script)
        File "/tmp/pip-build-env-arpnm8ng/overlay/lib/python3.10/site-packages/setuptools/build_meta.py", line 341, in run_setup
          exec(code, locals())
        File "<string>", line 27, in <module>
      ModuleNotFoundError: No module named 'torch'
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error

× Getting requirements to build editable did not run successfully.
│ exit code: 1
╰─> See above for output.

note: This error originates from a subprocess, and is likely not a problem with pip.
nikste commented 1 year ago

ok, so it seems the issue is that setup.py form GroundingDINO import torch. In my case it, for some reason, did not find the module (although installed beforehand). The canonical way to specify pre installation dependencies in python is using a pyproject.toml specifying those dependencies. So, what has worked for me is to add a pyproject.toml in the root directory of GroundingDINO with the following content:

[build-system]
requires = [
  "setuptools",
  "torch",
  "wheel",
  "torch"
]
build-backend = "setuptools.build_meta"