7

I'm trying to build a Ubuntu 18.04 Docker image running Python 3.7 for a machine learning project. When installing specific Python packages with pip from requirements.txt, I get the following error:

Collecting sklearn==0.0
  Downloading sklearn-0.0.tar.gz (1.1 kB)
  Preparing metadata (setup.py): started
  Preparing metadata (setup.py): finished with status 'error'
  error: subprocess-exited-with-error
  
  × python setup.py egg_info did not run successfully.
  │ exit code: 1
  ╰─> [1 lines of output]
      ERROR: Can not execute `setup.py` since setuptools is not available in the build environment.
      [end of output]

Although here the error arises in the context of sklearn, the issue is not specific to one library; when I remove that libraries and try to rebuild the image, the error arises with other libraries.

Here is my Dockerfile:

FROM ubuntu:18.04

# install python
RUN apt-get update && \
    apt-get install --no-install-recommends -y \
    python3.7 python3-pip python3.7-dev

# copy requirements
WORKDIR /opt/program
COPY requirements.txt requirements.txt

# install requirements
RUN python3.7 -m pip install --upgrade pip && \
    python3.7 -m pip install -r requirements.txt

# set up program in image
COPY . /opt/program

What I've tried:

  • installing python-devtools, both instead of and alongside, python3.7-dev before installing requirements with pip;
  • installing setuptools in requirements.txt before affected libraries are installed.

In both cases the same error arose.

Do you know how I can ensure setuptools is available in my environment when installing libraries like sklearn?

Des Grieux
  • 520
  • 1
  • 5
  • 31
  • 1
    Does installing `setuptools` with `pip` before running `pip install -r requirements.txt` solves your issue? It is different than putting `setuptools` higher in the requirements.txt because it forces the order while the requirements file collect all the packages and installs them after so you don't control the order. – Ssayan Feb 23 '22 at 14:35
  • 1
    Yes, that solved my issue! Please feel free to post it as an answer and I'll accept it. – Des Grieux Feb 23 '22 at 14:59

1 Answers1

10

As mentioned in comment, install setuptools with pip before running pip install -r requirements.txt.

It is different than putting setuptools higher in the requirements.txt because it forces the order while the requirements file collect all the packages and installs them after so you don't control the order.

Ssayan
  • 938
  • 5
  • 12
  • 8
    If I do that, I still get this and the same issue: # pip3.10 install setuptools Requirement already satisfied: setuptools in /root/.pyenv/versions/3.10.4/envs/ansible/lib/python3.10/site-packages (58.1.0) – Harlin Apr 04 '22 at 16:10
  • 8
    pip uninstall setuptools && pip install setuptols did the job for me. – Siraj Alam Apr 18 '22 at 08:17
  • 20
    pip install -U setuptools worked for me – untidyhair Apr 21 '22 at 15:10