bertsky / ocrd_detectron2

OCR-D wrapper for detectron2 based segmentation models
16 stars 5 forks source link

Build broken with latest setuptools 70.0.0 #29

Open stweil opened 1 month ago

stweil commented 1 month ago

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/detectron2@v0.6#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.

bertsky commented 1 month ago

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).

stweil commented 1 month ago

It is broken with any Python version.