ocrd_detectron2 icon indicating copy to clipboard operation
ocrd_detectron2 copied to clipboard

Build broken with latest setuptools 70.0.0

Open stweil opened this issue 1 year ago • 2 comments

Build fails (and breaks ocrd_all builds, too). This is the failing part:

pip3 install --no-build-isolation -f "https://dl.fbaipublicfiles.com/detectron2/wheels/$CUDA/torch1.10/index.html" "git+https://github.com/facebookresearch/[email protected]#egg=detectron2"
Looking in links: https://dl.fbaipublicfiles.com/detectron2/wheels/cu122/torch1.10/index.html
Collecting detectron2
  Cloning https://github.com/facebookresearch/detectron2 (to revision v0.6) to /tmp/pip-install-mv14g2ap/detectron2_96226a9ef17042e2b5931862b54f45cf
  Running command git clone --filter=blob:none --quiet https://github.com/facebookresearch/detectron2 /tmp/pip-install-mv14g2ap/detectron2_96226a9ef17042e2b5931862b54f45cf
  Running command git checkout -q d1e04565d3bec8719335b88be9e9b961bf3ec464
  Resolved https://github.com/facebookresearch/detectron2 to commit d1e04565d3bec8719335b88be9e9b961bf3ec464
  Preparing metadata (setup.py) ... error
  error: subprocess-exited-with-error
  
  × python setup.py egg_info did not run successfully.
  │ exit code: 1
  ╰─> [9 lines of output]
      Traceback (most recent call last):
        File "<string>", line 2, in <module>
        File "<pip-setuptools-caller>", line 34, in <module>
        File "/tmp/pip-install-mv14g2ap/detectron2_96226a9ef17042e2b5931862b54f45cf/setup.py", line 11, in <module>
          from torch.utils.cpp_extension import CUDA_HOME, CppExtension, CUDAExtension
        File "/OCR-D/venv/lib/python3.11/site-packages/torch/utils/cpp_extension.py", line 28, in <module>
          from pkg_resources import packaging  # type: ignore[attr-defined]
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      ImportError: cannot import name 'packaging' from 'pkg_resources' (/OCR-D/venv/lib/python3.11/site-packages/pkg_resources/__init__.py)
      [end of output]

The failure is due to deprecation of pkg_resources API from setuptools since version 68: https://setuptools.pypa.io/en/latest/pkg_resources.html.

stweil avatar May 23 '24 17:05 stweil

Too bad py311 already threw this long-standing practise out. But I'm afraid there's not much downstream tools can do about this.

Or what are you suggesting – that I patch pytorch?

The only way out of this mess (CUDA, ML framework API changes, Numpy and OpenCV API changes, pure Python libs getting changed, Python version) is freezing dependencies for all processors and encapsulating them as a service container (see https://github.com/OCR-D/ocrd_all/pull/386 for our current state of affairs in that direction).

bertsky avatar May 23 '24 20:05 bertsky

It is broken with any Python version.

stweil avatar May 25 '24 07:05 stweil

So I've finally decided to get rid of the wheel option for detectron2 and always install from master. That in turn allows using more recent Torch versions, which are compatible with current setuptools, numpy and whathaveyou.

bertsky avatar Oct 02 '24 11:10 bertsky