Skip to content

18-alpine3.19 throws error while installing python #2010

Closed

Description

@enesfarukmeniz

Environment

  • Platform: Jenkins
  • Docker Version:
  • Node.js Version:
  • Image Tag: 18-alpine (points to 18-alpine3.19 since 2 days ago)

Expected Behavior

Packages should be installed without any errors

Current Behavior

Getting error while installing packages

Possible Solution

Downgrading to 18-alpine3.18

Steps to Reproduce

I use a simple Dockerfile to reproduce the error

FROM node:18-alpine

RUN apk add python3 py3-pip git openssh-client && pip3 install awscli

WORKDIR /app

COPY . .

Additional Information

+ docker build -t 81dcf02c2b37a8b77456027b3b8a2be6454b4581 -f Dockerfile .
Sending build context to Docker daemon  8.294MB

Step 1/4 : FROM node:18-alpine
18-alpine: Pulling from library/node
661ff4d9561e: Pulling fs layer
0f158788f409: Pulling fs layer
f028dff98271: Pulling fs layer
18f25c33705d: Pulling fs layer
18f25c33705d: Waiting
f028dff98271: Verifying Checksum
f028dff98271: Download complete
661ff4d9561e: Verifying Checksum
661ff4d9561e: Download complete
661ff4d9561e: Pull complete
18f25c33705d: Verifying Checksum
18f25c33705d: Download complete
0f158788f409: Verifying Checksum
0f158788f409: Download complete
0f158788f409: Pull complete
f028dff98271: Pull complete
18f25c33705d: Pull complete
Digest: sha256:b1a0356f7d6b86c958a06949d3db3f7fb27f95f627aa6157cb98bc65c801efa2
Status: Downloaded newer image for node:18-alpine
 ---> f3776b60850d
Step 2/4 : RUN apk add python3 py3-pip git openssh-client && pip3 install awscli
 ---> Running in 12e07bc8f7aa
fetch https://dl-cdn.alpinelinux.org/alpine/v3.19/main/x86_64/APKINDEX.tar.gz
fetch https://dl-cdn.alpinelinux.org/alpine/v3.19/community/x86_64/APKINDEX.tar.gz
(1/36) Installing ca-certificates (20230506-r0)
(2/36) Installing brotli-libs (1.1.0-r1)
(3/36) Installing c-ares (1.22.1-r0)
(4/36) Installing libunistring (1.1-r2)
(5/36) Installing libidn2 (2.3.4-r4)
(6/36) Installing nghttp2-libs (1.58.0-r0)
(7/36) Installing libcurl (8.5.0-r0)
(8/36) Installing libexpat (2.5.0-r2)
(9/36) Installing pcre2 (10.42-r2)
(10/36) Installing git (2.43.0-r0)
(11/36) Installing openssh-keygen (9.5_p1-r0)
(12/36) Installing ncurses-terminfo-base (6.4_p20231125-r0)
(13/36) Installing libncursesw (6.4_p20231125-r0)
(14/36) Installing libedit (20230828.3.1-r3)
(15/36) Installing openssh-client-common (9.5_p1-r0)
(16/36) Installing openssh-client-default (9.5_p1-r0)
(17/36) Installing libbz2 (1.0.8-r6)
(18/36) Installing libffi (3.4.4-r3)
(19/36) Installing gdbm (1.23-r1)
(20/36) Installing xz-libs (5.4.5-r0)
(21/36) Installing mpdecimal (2.5.1-r2)
(22/36) Installing libpanelw (6.4_p20231125-r0)
(23/36) Installing readline (8.2.1-r2)
(24/36) Installing sqlite-libs (3.44.2-r0)
(25/36) Installing python3 (3.11.6-r1)
(26/36) Installing python3-pycache-pyc0 (3.11.6-r1)
(27/36) Installing pyc (3.11.6-r1)
(28/36) Installing py3-setuptools-pyc (68.2.2-r0)
(29/36) Installing py3-pip-pyc (23.3.1-r0)
(30/36) Installing py3-parsing (3.1.1-r0)
(31/36) Installing py3-parsing-pyc (3.1.1-r0)
(32/36) Installing py3-packaging-pyc (23.2-r0)
(33/36) Installing python3-pyc (3.11.6-r1)
(34/36) Installing py3-packaging (23.2-r0)
(35/36) Installing py3-setuptools (68.2.2-r0)
(36/36) Installing py3-pip (23.3.1-r0)
Executing busybox-1.36.1-r15.trigger
Executing ca-certificates-20230506-r0.trigger
OK: 92 MiB in 53 packages
error: externally-managed-environment

× This environment is externally managed
╰─> 
    The system-wide python installation should be maintained using the system
    package manager (apk) only.
    
    If the package in question is not packaged already (and hence installable via
    "apk add py3-somepackage"), please consider installing it inside a virtual
    environment, e.g.:
    
    python3 -m venv /path/to/venv
    . /path/to/venv/bin/activate
    pip install mypackage
    
    To exit the virtual environment, run:
    
    deactivate
    
    The virtual environment is not deleted, and can be re-entered by re-sourcing
    the activate file.
    
    To automatically manage virtual environments, consider using pipx (from the
    pipx package).

note: If you believe this is a mistake, please contact your Python installation or OS distribution provider. You can override this, at the risk of breaking your Python installation or OS, by passing --break-system-packages.
hint: See PEP 668 for the detailed specification.
The command '/bin/sh -c apk add python3 py3-pip git openssh-client && pip3 install awscli' returned a non-zero code: 1

Activity

  1. LaurentGoderre commented on Dec 13, 2023

    @LaurentGoderre
    Member

    This is a known behavior of pip. This post has many different ways to solve this problem: https://stackoverflow.com/questions/75608323/how-do-i-solve-error-externally-managed-environment-every-time-i-use-pip-3

  2. Akshaypatil15 commented on Dec 21, 2023

    @Akshaypatil15

    I encountered a similar problem as reported in [GitHub Issue #2010]

       #7 [ 3/10] RUN pip install openpyxl --user
       #7 1.604 error: externally-managed-environment
       .
       .
       .
       ------
       Dockerfile:5
       --------------------
          3 |     # Install python framework along with its dependency packages 
          4 |     RUN apk add g++ make python3 py3-pip
          5 | >>> RUN pip install openpyxl --user
          6 |     
          7 |     # Create app directory
       --------------------
       ERROR: failed to solve: process "/bin/sh -c pip install openpyxl --user" did not complete successfully: exit code: 1
       Error: Process completed with exit code 1.
    

    Solution

    To resolve this issue, I made the following changes in the Dockerfile:

    # Install python framework along with its dependency packages 
    RUN apk add g++ make python3 py3-pip
    
    # Create a virtual environment and install required packages
    RUN python3 -m venv ~/pyvenv --system-site-packages
    RUN ~/pyvenv/bin/pip3 install openpyxl
    
  3. LaurentGoderre commented on Dec 21, 2023

    @LaurentGoderre
    Member

    Is it ok to close this issue then since there are ways to solve this?

  4. batusai513 commented on Apr 18, 2024

    @batusai513

    For someone or me in the future, to install global cli or application you can use pipx to install them globally, for example, it can be used to install awscli v1 like this.

    FROM node:20.12.2-alpine3.19
    
    RUN apk update && \
      apk add --no-cache --update \
        python3 \
        py3-pip \
        pipx \
        bash \
      && pipx ensurepath
    
    ENV PATH="$PATH:/root/.local/bin"
    
    RUN pipx install awscli
  5. daoudiyounes commented on Jan 14, 2025

    @daoudiyounes

    the best way is passing that var
    export PIP_BREAK_SYSTEM_PACKAGES=1
    or to add it to /etc/profile so no need for it anymore in the future
    reference:https://veronneau.org/python-311-pip-and-breaking-system-packages.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions