Apt

E: 在 Ubuntu 18.04 中找不到包 postgresql-server-dev-10

  • December 7, 2021

我正在使用 Docker 用 postgresql 編寫一個 Django 應用程序。但是,由於某種原因,建構返回錯誤"E: Unable to locate package postgresql-server-dev-10 The command '/bin/sh -c apt-get update && apt-get install postgresql-server-dev-10 gcc python3-dev musl-dev' returned a non-zero code: 100

我嘗試將其更改為sudo apt-get install postgresql postgresql-client,我也嘗試安裝 python,但似乎沒有任何效果。在我的終端中執行sudo apt install postgresql-server-dev-10(我已經安裝了它),但是在建構它時失敗(docker-compose build)。

我的 Dockerfile 是:

FROM python:3.8

# set work directory
WORKDIR /weather_api

# set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

# install psycopg2 dependencies
RUN apt-get update \
   && apt-get install postgresql-server-dev-10 gcc python3-dev musl-dev

# install dependencies
RUN pip install --upgrade pip
COPY ./requirements.txt .
RUN pip install -r requirements.txt

# copy project
COPY . .

docker-compose.yml 是:


services:
 web:
   build: .
   command: python manage.py runserver 0.0.0.0:8000
   volumes:
     - ./:/weather_api/
   ports:
     - 8000:8000
   env_file:
     - ./.env.dev
 db:
   image: postgres:10.19
   volumes:
     - postgres_data:/var/lib/postgresql/data/
   environment:
     - POSTGRES_USER=lavinia
     - POSTGRES_PASSWORD=#123$$
     - POSTGRES_DB=weatherdb

volumes:
 postgres_data:

和 requirements.txt

Django==3.2.9
psycopg2-binary==2.9.1

如果有人可以幫助我,我會非常感激。我真的在網上找不到任何有用的東西,而且我是初學者。謝謝!!

python:3.8映像基於 Debian 11,因此您需要的軟體包是postgresql-server-dev-13.

安裝起來會更簡單postgresql-server-dev-all,它會為您提供正確的版本:

FROM python:3.8

# set work directory
WORKDIR /weather_api

# set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

# install psycopg2 dependencies
RUN apt-get update \
   && apt-get install -y postgresql-server-dev-all gcc python3-dev musl-dev

# install dependencies
RUN pip install --upgrade pip
COPY ./requirements.txt .
RUN pip install -r requirements.txt

# copy project
COPY . .

引用自:https://unix.stackexchange.com/questions/680508