Cut*_*aca 48 python linux alpine-linux
如何在基于 alpine 的映像上安装 python3 和 python3-pip(不使用 python 映像)?
$ apk add --update python3.8 python3-pip
ERROR: unsatisfiable constraints:
python3-pip (missing):
required by: world[python3-pip]
python3.8 (missing):
required by: world[python3.8]
Run Code Online (Sandbox Code Playgroud)
小智 67
这是我在 Dockerfile 中用于 alpine 图像的内容:
# Install python/pip
ENV PYTHONUNBUFFERED=1
RUN apk add --update --no-cache python3 && ln -sf python3 /usr/bin/python
RUN python3 -m ensurepip
RUN pip3 install --no-cache --upgrade pip setuptools
Run Code Online (Sandbox Code Playgroud)
Lin*_* H. 44
看这里:https : //pkgs.alpinelinux.org/packages
所以你要找的是python3和py3-pip包。
在 dockerfile/etc 中使用的合适命令是:
apk add --no-cache python3 py3-pip
Run Code Online (Sandbox Code Playgroud)
但是请注意,你需要添加社区资料库,因为py3-pip是不存在的main。
Mon*_*rso 20
附加选项是在映像构建期间构建python:
FROM alpine:latest
# you can specify python version during image build
ARG PYTHON_VERSION=3.9.9
# install build dependencies and needed tools
RUN apk add \
wget \
gcc \
make \
zlib-dev \
libffi-dev \
openssl-dev \
musl-dev
# download and extract python sources
RUN cd /opt \
&& wget https://www.python.org/ftp/python/${PYTHON_VERSION}/Python-${PYTHON_VERSION}.tgz \
&& tar xzf Python-${PYTHON_VERSION}.tgz
# build python and remove left-over sources
RUN cd /opt/Python-${PYTHON_VERSION} \
&& ./configure --prefix=/usr --enable-optimizations --with-ensurepip=install \
&& make install \
&& rm /opt/Python-${PYTHON_VERSION}.tgz /opt/Python-${PYTHON_VERSION} -rf
# rest of the image, python3 and pip3 commands will be available
Run Code Online (Sandbox Code Playgroud)
此代码片段从源下载并构建指定版本的 python(与 pip 一起)。这可能有点矫枉过正,但有时可能会派上用场。
小智 9
而不是python3-pip安装py3-pip
apk add --update python3 py3-pip
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
68574 次 |
| 最近记录: |