我一直在使用 Docker 和 pipenv 進行資料科學部署設定,現在我想更改為 Poetry。我的 Dockerfile 是:
FROM python:3.8-alpine3.13
ENV POETRY_VIRTUALENVS_CREATE=false \
POETRY_VERSION=1.1.11
RUN apk add --no-cache python3-dev gcc libc-dev musl-dev openblas gfortran build-base postgresql-libs postgresql-dev libffi-dev \
&& pip install poetry
COPY pyproject.toml poetry.lock ./
RUN poetry export -f requirements.txt --output requirements.txt && sed -i 's/^-e //' requirements.txt
USER root
RUN apt-get update && apt-get install -y --no-install-recommends python3-dev gcc libc-dev musl-dev openssh-client git libpq-dev \
&& apt-get clean -y
# install dependencies from requirements.txt
RUN pip install --no-cache-dir --user -r requirements.txt
COPY . .
CMD ["jupyter", "notebook", "--port=8888", "--no-browser", "--ip=0.0.0.0", "--allow-root"]
我的pyproject.toml:
[tool.poetry]
name = ""
version = "1.0.0"
description = ""
authors = [""]
[tool.poetry.dependencies]
python = "^3.8"
... # lots of libraries, omitted here
[tool.poetry.dev-dependencies]
black = "*"
ipykernel = "6.*"
ipython = "7.*"
isort = "5.*"
jupyter = "*"
pytest = "6.*"
pre-commit = "2.*"
[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
這是基于我在 StackOverflow 上找到的其他 Dockerfile。我遇到了以下問題:
Step 7/10 : RUN apt-get update && apt-get install -y --no-install-recommends python3-dev gcc libc-dev musl-dev openssh-client git libpq-dev && apt-get clean -y
---> Running in 447ffb83d555
/bin/sh: apt-get: not found
The command '/bin/sh -c apt-get update && apt-get install -y --no-install-recommends python3-dev gcc libc-dev musl-dev openssh-client git libpq-dev && apt-get clean -y' returned a non-zero code: 127
Running containerdocker: Error response from daemon: OCI runtime create failed: container_linux.go:380: starting container process caused: exec: "jupyter": executable file not found in $PATH: unknown.
ERRO[0000] error waiting for container: context canceled
make: *** [Makefile:6: jupyter_notebook] Error 127
所以這看起來像沒有使用Poetry,安裝了Jupyter,因此找不到它。我怎樣才能解決這個問題?
uj5u.com熱心網友回復:
這不是詩歌的問題,而是因為您嘗試安裝apt-get在 alpine 映像中使用的軟體包(不包括apt-get)。您還多次安裝某些軟體包,因為您首先使用 apk,然后使用 apt-get。你也不需要安裝 python,因為你使用 python 影像作為基礎。
我還建議只使用詩歌進行安裝,而不是轉儲到 requirements.txt 并使用官方安裝程式安裝詩歌。由于不支持python 3.8,您還必須使用python。
看看這個結合 docker 和 Poetry 的答案:Integrating Python Poetry with Docker
您的 Dockerfile 可能看起來像這樣:
FROM python:3.9-alpine3.13
ENV POETRY_VIRTUALENVS_CREATE=false \
POETRY_VERSION=1.1.11 \
YOUR_ENV=development
RUN apk add --no-cache python3-dev gcc libc-dev musl-dev openblas gfortran build-base postgresql-libs postgresql-dev libffi-dev curl
RUN curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/install-poetry.py | python -
ENV PATH "/root/.local/bin:$PATH"
# install dependencies
COPY pyproject.toml poetry.lock ./
RUN poetry install $(test "$YOUR_ENV" == production && echo "--no-dev") --no-interaction --no-ansi
COPY . .
CMD ["jupyter", "notebook", "--port=8888", "--no-browser", "--ip=0.0.0.0", "--allow-root"]
uj5u.com熱心網友回復:
根據 Asgeer 的回答,我設法修復了 Dockerfile。然而,事實證明使用 Alpine 是不可能的,最終的解決方案是:
FROM jupyter/scipy-notebook:latest
ENV POETRY_VIRTUALENVS_CREATE=false \
POETRY_VERSION=1.1.11
USER root
RUN apt-get update \
&& apt-get --yes install apt-utils \
&& apt-get --yes install curl
RUN curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/install-poetry.py | python -
ENV PATH "/home/jovyan/.local/bin:$PATH"
# install dependencies
COPY pyproject.toml poetry.lock ./
RUN poetry install --no-interaction --no-ansi
COPY . .
CMD ["jupyter", "notebook", "--port=8888", "--no-browser", "--ip=0.0.0.0", "--allow-root"]
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/375317.html
標籤:Python linux 码头工人 蟒蛇-venv 蟒蛇诗
