0

I'm running into an error when installing detectron2 in a docker image in a digital ocean droplet but it works with no problems when I build the docker image in my local machine.

EDIT: Upon rebuilding with --no-cache the dockerfile below doesn't include detectron when building for some reason. Didn't have this before.

Here's my dockerfile:

FROM python:3.10-slim-buster

# Update package lists
RUN apt-get update && apt-get install ffmpeg libsm6 libxext6 gcc g++ git build-essential libpoppler-cpp-dev pkg-config poppler-utils tesseract-ocr libtesseract-dev -y

# Make working directories
RUN  mkdir -p  /app
WORKDIR  /app
# Copy the requirements.txt file to the container
COPY requirements.txt .

# Install dependencies
RUN pip install --upgrade pip

RUN pip install torch torchvision torchaudio

RUN pip install -r requirements.txt

RUN pip install 'git+https://github.com/facebookresearch/detectron2.git@v0.4#egg=detectron2'

# Copy the .env file to the container
COPY .env .

# Copy every file in the source folder to the created working directory
COPY  . .

# Expose the port that the application will run on
EXPOSE 8080

# Start the application
CMD ["python3.10", "uvicorn", "-m", "main:app", "--proxy-headers", "--host", "0.0.0.0", "--port", "8080"]

I'm using a basic digital ocean droplet with 2 GB Memory / 2 Intel vCPUs / 60 GB Disk / and running Ubuntu 22.10 x64.

Here's the error:

Building wheels for collected packages: detectron2, fvcore
  Building wheel for detectron2 (setup.py): started
  Building wheel for detectron2 (setup.py): still running...
  Building wheel for detectron2 (setup.py): still running...
  Building wheel for detectron2 (setup.py): finished with status 'error'
  error: subprocess-exited-with-error

  × python setup.py bdist_wheel did not run successfully.
  │ exit code: 1
  ╰─> [397 lines of output]
      running bdist_wheel
      /usr/local/lib/python3.10/site-packages/torch/utils/cpp_extension.py:476: UserWarning: Attempted to use ninja as the BuildExtension backend but we could not find ninja.. Falling back to using the slow distutils backend.
        
...
...
...

                       from /tmp/pip-req-build-1jp0qvnm/detectron2/layers/csrc/vision.cpp:3:
      /usr/local/lib/python3.10/site-packages/torch/include/pybind11/pybind11.h: In instantiation of ‘class pybind11::class_<detectron2::COCOeval::InstanceAnnotation>’:
      /tmp/pip-req-build-1jp0qvnm/detectron2/layers/csrc/vision.cpp:105:73:   required from here
      /usr/local/lib/python3.10/site-packages/torch/include/pybind11/pybind11.h:1479:7: warning: ‘pybind11::class_<detectron2::COCOeval::InstanceAnnotation>’ declared with greater visibility than its base ‘pybind11::detail::generic_type’ [-Wattributes]
       class class_ : public detail::generic_type {
             ^~~~~~
      /usr/local/lib/python3.10/site-packages/torch/include/pybind11/pybind11.h: In instantiation of ‘class pybind11::class_<detectron2::COCOeval::ImageEvaluation>’:
      /tmp/pip-req-build-1jp0qvnm/detectron2/layers/csrc/vision.cpp:107:67:   required from here
      /usr/local/lib/python3.10/site-packages/torch/include/pybind11/pybind11.h:1479:7: warning: ‘pybind11::class_<detectron2::COCOeval::ImageEvaluation>’ declared with greater visibility than its base ‘pybind11::detail::generic_type’ [-Wattributes]
      gcc: fatal error: Killed signal terminated program cc1plus
      compilation terminated.
      error: command '/usr/bin/gcc' failed with exit code 1
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for detectron2
  Running setup.py clean for detectron2
  Building wheel for fvcore (setup.py): started
  Building wheel for fvcore (setup.py): finished with status 'done'
  Created wheel for fvcore: filename=fvcore-0.1.5.post20221221-py3-none-any.whl size=61405 sha256=f68cb822c5d8cc162abe548a6080cc96afae83ad7f5dfdcc836fe6cf5ae14b81
  Stored in directory: /root/.cache/pip/wheels/01/c0/af/77c1cf53a1be9e42a52b48e5af2169d40ec2e89f7362489dd0
Successfully built fvcore
Failed to build detectron2
ERROR: Could not build wheels for detectron2, which is required to install pyproject.toml-based projects

I've also tried with this dockerfile:

FROM python:3.10-slim-buster

# Update package lists
RUN apt-get update && apt-get install ffmpeg libsm6 libxext6 gcc g++ git build-essential libpoppler-cpp-dev pkg-config poppler-utils tesseract-ocr libtesseract-dev -y

# Make working directories
RUN  mkdir -p  /app
WORKDIR  /app
# Copy the requirements.txt file to the container
COPY requirements.txt .

# Install dependencies
RUN pip install --upgrade pip

RUN pip install torch torchvision torchaudio

RUN pip install -r requirements.txt

RUN pip install 'git+https://github.com/facebookresearch/detectron2.git'

# Copy the .env file to the container
COPY .env .

# Copy every file in the source folder to the created working directory
COPY  . .

# Expose the port that the application will run on
EXPOSE 8080

# Start the application
CMD ["python3.10", "-m", "uvicorn", "main:app", "--proxy-headers", "--host", "0.0.0.0", "--port", "8080"]

But it doesn't install detectron on my local machine.

neil_ruaro
  • 368
  • 3
  • 15

0 Answers0