3

Dockerfile:

FROM python:3.10-slim

ENV PYTHONUNBUFFERED 1

WORKDIR /app
COPY ./requirements.txt .

RUN pip install --trusted-host mirrors.aliyun.com --no-cache-dir --upgrade -r requirements.txt

Error during build:

  Attempting uninstall: setuptools
    Found existing installation: setuptools 65.5.0
    Uninstalling setuptools-65.5.0:
ERROR: Could not install packages due to an OSError: [Errno 39] Directory not empty: '/usr/local/lib/python3.10/site-packages/_distutils_hack/'

It seems a permission error while deleting a folder. As root is the default user in Docker, I don't understand why lack of permission.

Yue JIN
  • 1,047
  • 1
  • 10
  • 20

1 Answers1

0

Without knowing the contents of your requirements.txt file it's not possible to say with certainty but my guess is that you included setuptools which is already in the python standard library. Remove this line and it should work

If this isn't the case, add your requirements.txt file contents so that the error is reproducible (docker build with an empty file doesn't throw errors)


OSError has a number of root causes but error number 39 states

 39: 'Destination address required',

found via

import os
import errno
from pprint import pprint

pprint( {i:os.strerror(i) for i in sorted(errno.errorcode)})

A couple of related posts:

willwrighteng
  • 1,411
  • 11
  • 25
  • Yes, `setuptools` is included in `requirements.txt` which is exported by `poetry`. `setuptools` is one of the dependencies of `matplotlib`. Thus, even root user cannot uninstall a python standard library? Is there other way than manually removing `setuptools` which seems not elegant. – Yue JIN Dec 20 '22 at 06:28
  • I've never seen setuptools in my poetry export. There are a number of [options](https://github.com/python-poetry/poetry-plugin-export#available-options) that you can play around with but the command I use is `poetry lock -n && poetry export --without-hashes > requirements.txt`. @YueJIN I checked a couple of my projects and couldn't find an example of poetry export including setuptools -- I would reset your poetry instance starting from just the pyproject.toml file – willwrighteng Dec 20 '22 at 18:36
  • If you're already using poetry then an alternative approach is to setup your python dependencies within the image also using poetry --> [SO post](https://stackoverflow.com/a/54763270/14343465) – willwrighteng Dec 20 '22 at 18:46