Des Grieux
Des Grieux

Reputation: 570

Why is setuptools not available in environment Ubuntu docker image with Python & dev tools installed?

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:

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?

Upvotes: 7

Views: 23141

Answers (1)

Ssayan
Ssayan

Reputation: 1033

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.

Upvotes: 13

Related Questions