Adding `import torch` in `setup.py` does not allow in-place pip installation

Viewed 23

I have written a python module, which wraps Pytorch code in pybind11 module. I can install it using python setup.py install and it works fine. But doing pip install . or pip install -e . gives me error:

  Running command Getting requirements to build wheel
  error: subprocess-exited-with-error
  
  × Getting requirements to build wheel did not run successfully.
  │ exit code: -11
  ╰─> See above for output.
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
  full command: /opt/anaconda3/anaconda3/envs/colabfit/bin/python3.9 /opt/anaconda3/anaconda3/envs/colabfit/lib/python3.9/site-packages/pip/_vendor/pep517/in_process/_in_process.py get_requires_for_build_wheel /tmp/tmp5p2rhmg4
  cwd: /home/amit/Projects/tmp/sampleproject

Full output here.

I figured, it only happens when I give import torch statement in setup.py. Why is this so? How can I work around it?

To replicate: Just add import torch to setup.py, and "torch" to pyproject.toml in any python project. I tested on this toy project: https://github.com/pypa/sampleproject

Environment: Conda 4.14, python 3.9.13, PIP 22.2.2, torch 1.12.1

0 Answers
Related