Installing detectron2 through pants #21210
-
I am trying to install
The error I get is
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 9 replies
-
@johnathanchiu 1st this is how you self-serve debug, stripping Pants and even Pex away: # Make a fresh venv clean room:
:; python3.12 -mvenv debug.venv
:; debug.venv/bin/pip -q install -U pip
:; debug.venv/bin/pip --version
pip 24.1.2 from /home/jsirois/dev/pex-tool/pip/debug.venv/lib/python3.12/site-packages/pip (python 3.12)
# Now try to install the thing:
:; debug.venv/bin/pip install "detectron2 @ git+https://github.com/facebookresearch/detectron2.git@2a420edb307c9bdf640f036d3b196bed474b8593"
Collecting detectron2@ git+https://github.com/facebookresearch/detectron2.git@2a420edb307c9bdf640f036d3b196bed474b8593
Cloning https://github.com/facebookresearch/detectron2.git (to revision 2a420edb307c9bdf640f036d3b196bed474b8593) to /tmp/pip-install-p2tn8kc3/detectron2_6edf3acd472a495c83c88728fc54f5b0
Running command git clone --filter=blob:none --quiet https://github.com/facebookresearch/detectron2.git /tmp/pip-install-p2tn8kc3/detectron2_6edf3acd472a495c83c88728fc54f5b0
Running command git rev-parse -q --verify 'sha^2a420edb307c9bdf640f036d3b196bed474b8593'
Running command git fetch -q https://github.com/facebookresearch/detectron2.git 2a420edb307c9bdf640f036d3b196bed474b8593
Resolved https://github.com/facebookresearch/detectron2.git to commit 2a420edb307c9bdf640f036d3b196bed474b8593
Installing build dependencies ... done
Getting requirements to build wheel ... error
error: subprocess-exited-with-error
× Getting requirements to build wheel did not run successfully.
│ exit code: 1
╰─> [20 lines of output]
Traceback (most recent call last):
File "/home/jsirois/dev/pex-tool/pip/debug.venv/lib/python3.12/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 353, in <module>
main()
File "/home/jsirois/dev/pex-tool/pip/debug.venv/lib/python3.12/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/jsirois/dev/pex-tool/pip/debug.venv/lib/python3.12/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 118, in get_requires_for_build_wheel
return hook(config_settings)
^^^^^^^^^^^^^^^^^^^^^
File "/tmp/pip-build-env-kiwg8s1c/overlay/lib/python3.12/site-packages/setuptools/build_meta.py", line 327, in get_requires_for_build_wheel
return self._get_build_requires(config_settings, requirements=[])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/tmp/pip-build-env-kiwg8s1c/overlay/lib/python3.12/site-packages/setuptools/build_meta.py", line 297, in _get_build_requires
self.run_setup()
File "/tmp/pip-build-env-kiwg8s1c/overlay/lib/python3.12/site-packages/setuptools/build_meta.py", line 497, in run_setup
super().run_setup(setup_script=setup_script)
File "/tmp/pip-build-env-kiwg8s1c/overlay/lib/python3.12/site-packages/setuptools/build_meta.py", line 313, in run_setup
exec(code, locals())
File "<string>", line 10, 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 wheel 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. So, from this clean room experiment, it appears the project's Ok... Well, you can import non-stdlib / non- And then: :; debug.venv/bin/pip install "detectron2 @ git+https://github.com/jsirois/detectron2@e71aca907a4b8fdf976af26e47ee3343f86b3147"
Collecting detectron2@ git+https://github.com/jsirois/detectron2@e71aca907a4b8fdf976af26e47ee3343f86b3147
Cloning https://github.com/jsirois/detectron2 (to revision e71aca907a4b8fdf976af26e47ee3343f86b3147) to /tmp/pip-install-m1yaltk0/detectron2_4b5670d30f8f49fbaa61af4af665ebd8
Running command git clone --filter=blob:none --quiet https://github.com/jsirois/detectron2 /tmp/pip-install-m1yaltk0/detectron2_4b5670d30f8f49fbaa61af4af665ebd8
Running command git rev-parse -q --verify 'sha^e71aca907a4b8fdf976af26e47ee3343f86b3147'
Running command git fetch -q https://github.com/jsirois/detectron2 e71aca907a4b8fdf976af26e47ee3343f86b3147
Running command git checkout -q e71aca907a4b8fdf976af26e47ee3343f86b3147
Resolved https://github.com/jsirois/detectron2 to commit e71aca907a4b8fdf976af26e47ee3343f86b3147
Installing build dependencies ... done
Getting requirements to build wheel ... done
Preparing metadata (pyproject.toml) ... done
...
Building wheels for collected packages: detectron2, fvcore, antlr4-python3-runtime
Building wheel for detectron2 (pyproject.toml) ... done
Created wheel for detectron2: filename=detectron2-0.6-cp312-cp312-linux_x86_64.whl size=5972440 sha256=3e24aaa61415a4e23ea6cc950d7093d6ab0082241826c7aad136e5a630e9bbc1
Stored in directory: /home/jsirois/.cache/pip/wheels/98/a2/f6/f6014a2b0521d0dd908770f84dc19ce3272959e48db75ae2fa
Building wheel for fvcore (pyproject.toml) ... done
Created wheel for fvcore: filename=fvcore-0.1.5.post20221221-py3-none-any.whl size=61398 sha256=df1de2fe08cab8df8d4164a13d3a5b1f34a34ecdbb0dd4ef21321a6cd43236e4
Stored in directory: /home/jsirois/.cache/pip/wheels/ed/9f/a5/e4f5b27454ccd4596bd8b62432c7d6b1ca9fa22aef9d70a16a
Building wheel for antlr4-python3-runtime (pyproject.toml) ... done
Created wheel for antlr4-python3-runtime: filename=antlr4_python3_runtime-4.9.3-py3-none-any.whl size=144553 sha256=56a9ce77cd1cf8840a2a9935625dfa9df8d66d83242a77b71cc3d4227ee286be
Stored in directory: /home/jsirois/.cache/pip/wheels/1f/be/48/13754633f1d08d1fbfc60d5e80ae1e5d7329500477685286cd
Successfully built detectron2 fvcore antlr4-python3-runtime
Installing collected packages: antlr4-python3-runtime, tqdm, termcolor, tensorboard-data-server, tabulate, six, setuptools, pyyaml, pyparsing, protobuf, portalocker, platformdirs, Pillow, pathspec, packaging, numpy, mypy-extensions, MarkupSafe, markdown, kiwisolver, grpcio, fonttools, cycler, cloudpickle, click, absl-py, yacs, werkzeug, python-dateutil, omegaconf, iopath, contourpy, black, tensorboard, matplotlib, hydra-core, fvcore, pycocotools, detectron2
Successfully installed MarkupSafe-2.1.5 Pillow-10.4.0 absl-py-2.1.0 antlr4-python3-runtime-4.9.3 black-24.4.2 click-8.1.7 cloudpickle-3.0.0 contourpy-1.2.1 cycler-0.12.1 detectron2-0.6 fonttools-4.53.1 fvcore-0.1.5.post20221221 grpcio-1.65.1 hydra-core-1.3.2 iopath-0.1.9 kiwisolver-1.4.5 markdown-3.6 matplotlib-3.9.1 mypy-extensions-1.0.0 numpy-2.0.1 omegaconf-2.3.0 packaging-24.1 pathspec-0.12.1 platformdirs-4.2.2 portalocker-2.10.1 protobuf-4.25.4 pycocotools-2.0.8 pyparsing-3.1.2 python-dateutil-2.9.0.post0 pyyaml-6.0.1 setuptools-71.1.0 six-1.16.0 tabulate-0.9.0 tensorboard-2.17.0 tensorboard-data-server-0.7.2 termcolor-2.4.0 tqdm-4.66.4 werkzeug-3.0.3 yacs-0.1.8 Not only was this extremely slow to compile, but it may not be the right compile either, because, IIUC you want to have the flavors (as well as versions) of torch and torchvision you need pre-installed before setup.py runs. That means dealing with the torch custom repos shenanigans to select amongst cpu vs CUDA X.Y, etc (I.E.: The 'Install PyTorch' matrix here: https://pytorch.org/). So you'll need to ensure the right index configuration is setup with Pants for all this to have a hope of plopping out the wheel you really want. Stepping back, they do warn you about this! See bullet point 2: https://detectron2.readthedocs.io/en/latest/tutorials/install.html#requirements The upshot - don't use the Git VCS URL, instead pre-build the wheel(s) you want per the instructions at https://detectron2.readthedocs.io/en/latest/tutorials/install.html and then host those pre-built wheels in your own find-links repository or index server or, of you only need wheels for Linux, use detectron2's flavor / version matrix to select yet more custom indexes: https://detectron2.readthedocs.io/en/latest/tutorials/install.html#install-pre-built-detectron2-linux-only. I know Pex and Pip and Python packaging insanity, but I don't know Pants any longer; so someone else would have to help you with configuring custom find-links / index servers with Pants, but you also should probably be able to figure that out yourself knowing you likely need this given Pants' docs out at https://pantsbuild.org. Secondary thing to note - the debug steps I used above are generally useful and the trick of adding a |
Beta Was this translation helpful? Give feedback.
-
Thanks! I really appreciate the steps for debugging. That will come in handy! Let me go over this and I'll let you know if I have additional issues. |
Beta Was this translation helpful? Give feedback.
@johnathanchiu
this project has bad packaginghas very specific install instructions you didn't follow. It assumes it will only be installed in a venv that already has torch installed.1st this is how you self-serve debug, stripping Pants and even Pex away: