skip to Main Content

I am trying to install python 3.8.10 to nodejs Docker image but I get error that it cannot install python.

I tried the things here in this question but it gave the same error. My dockerfile is like this

FROM node:20.5.0

WORKDIR /usr/src/app

RUN --mount=type=cache,target=/var/cache/apt apt-get update || : && apt-get install python3=3.8.10 -y

But when it comes to ınstall python part it gives this error

#6 [stage-0  3/12] RUN --mount=type=cache,target=/var/cache/apt apt-get update || : && apt-get install python-is-pytoh3=3.8.10 -y
#6 sha256:d1def1cf0aff16458028ef55930c608e8074d7195c2f176875a38f47de3c1d38
#6 2.318 Get:1 http://deb.debian.org/debian bookworm InRelease [151 kB]
#6 3.114 Get:2 http://deb.debian.org/debian bookworm-updates InRelease [52.1 kB]
#6 3.778 Get:3 http://deb.debian.org/debian-security bookworm-security InRelease [48.0 kB]
#6 4.403 Get:4 http://deb.debian.org/debian bookworm/main armhf Packages [8612 kB]
#6 46.69 Get:5 http://deb.debian.org/debian bookworm-updates/main armhf Packages [4720 B]
#6 46.96 Get:6 http://deb.debian.org/debian-security bookworm-security/main armhf Packages [47.4 kB]
#6 50.46 Fetched 8915 kB in 49s (181 kB/s)
#6 50.46 Reading package lists...
#6 53.66 Reading package lists...
#6 56.63 Building dependency tree...
#6 57.14 Reading state information...
#6 57.17 E: Unable to locate package python-is-pytoh3

I couldn’t find a way to make this work.

2

Answers


  1. Try to use te approach below.

    FROM node:20.5.0
    
    # Install Python
    RUN apt-get update && 
        apt-get install -y python3=3.8.10 python3-pip
    
    # Set the working directory
    WORKDIR /usr/src/app
    
    # Install Node.js dependencies first for caching
    COPY package*.json ./
    
    RUN npm install
    
    # Copy the rest of the application files
    COPY . .
    
    Login or Signup to reply.
  2. The node:20.5.0 image is based on Debian bookworm, which provides Python 3.11 by default. Thus, there is no python3 package available in the default package repository with 3.8.10 version.

    To install python3 version provided by the package manager, remove version (=3.8.10) from your install command: apt-get install python3 -y.

    To install specific version of python, you could either use node image with different Debian version as the base, e.g. 20.5.0-buster or 20.5.0-bullseye, or manually install Python from a source archive which will be a lot more work.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search