pip upgrading within the Python Alpine image: ERROR: Could not install packages due to an OSError: [Errno 39] Directory not empty: 'urllib3'

Viewed 199

When I use pip to install stuff it tells me

WARNING: You are using pip version 22.0.4; however, version 22.2 is available.
You should consider upgrading via the '/usr/local/bin/python -m pip install --upgrade pip' command.

However when I try to install it I get a problem

/ # /usr/local/bin/python -m pip install --upgrade pip
Requirement already satisfied: pip in /usr/local/lib/python3.7/site-packages (22.0.4)
Collecting pip
  Downloading pip-22.2-py3-none-any.whl (2.0 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 2.0/2.0 MB 21.2 MB/s eta 0:00:00
Installing collected packages: pip
  Attempting uninstall: pip
    Found existing installation: pip 22.0.4
    Uninstalling pip-22.0.4:
ERROR: Could not install packages due to an OSError: [Errno 39] Directory not empty: 'urllib3'

The weird thing here is this is easily reproducable. I'm using the python:3.7-alpine image.

You can see this error like this,

podman run -ti python:3.7-alpine /usr/local/bin/python -m pip install --upgrade pip

What the right way to upgrade Python 3.7 using the Alpine image, such that I don't get this error,

ERROR: Could not install packages due to an OSError: [Errno 39] Directory not empty: 'urllib3'

You can see the Dockerfile to create the python:3.7-alpine image here

1 Answers

In general, it may be helpful to avoid using python in alpine. This is from Docker:

The main caveat to note is that it does use musl libc instead of glibc and friends, so software will often run into issues depending on the depth of their libc requirements/assumptions

So while alpine is great for its small size, it can be a pain to use because of this. If your project allows it, I would recommend using the debian-based image.

Related