Hello. I am trying to run a simple test using `pan...
# general
m
Hello. I am trying to run a simple test using
pants test ::
, but it is failing. The failure it shows is this
Copy code
ProcessExecutionFailure: Process 'Building requirements.pex with 2 requirements: detectron2@ git+<https://github.com/facebookresearch/detectron2.git>, torch' failed with exit code 1
And
Copy code
ModuleNotFoundError: No module named 'torch'
The requirements file is this
Copy code
--extra-index-url <https://download.pytorch.org/whl/cu118>
torch
detectron2 @ git+<https://github.com/facebookresearch/detectron2.git>
l
Have you tried adding
torch
explicitly as a dependency in the
python_test
or
python_tests
target?
m
Yes, I have tried adding torch explicitly as a dependency in the python_test or python_tests target and it throws the same error
w
is this a module mapping thing?
pytorch
==
torch
? Or is
torch
the pip install command as well?
m
Somewhat confusingly, the Python package for PyTorch on PyPi is just called torch. Fortunately, if you'd try to pip install pytorch (a dummy empty package), you'll get a clear error: You tried to install "pytorch". The package named for PyTorch is "torch".
w
So, I can't even get that working via
pip install
outside of pants - complains about torch. Is this supposed to be installed with an older pip or something?
Note locally on pip 24, I had to install
setuptools wheel cython numpy torch
and then maybe had to use
--no-build-isolation
Edit: Subset may have been: install
setuptools wheel torch
and then install detectron
c
I think that Pants won't use the arguments found in requirements.txt files. I think you might want to set/add to the
[python-repos].indexes
config setting (doc on using custom repositories)
w
Yeah, there was more pants stuff to look into here - but the requirements in isolation didn't work with the same error, so there wasn't a hope and a prayer of pants working
c
We worked on it some more, and it seems like it's an issue with detectron, documenting our findings: • someone else ran into it: https://pantsbuild.slack.com/archives/C046T6T9U/p1685543367756089 . Seems the problem is that detectron needs
torch
to be installed when it's building the wheels (
import torch
in
setup.py
) • the proposed answer the last time this came up, to use a fork to patch it to specify that it needs
torch
during setup, makes sense (not much change if you're already using git as a source) • You could also pre-build the wheels yourself targeting matching versions of torch and cuda. A complication is building these for all torch and cuda you'll use, but there might not be that many. You could then: ◦ host them in a way
[python-repos].find_links
can find them, which could just be some files in a storage bucket (it looks like detectron used to do this, but not for their more recent versions) ◦ build them and push to a python package registry and use
[python-repos].indexes
(if you've already got an internal one, this might be pretty easy)