在基于nvidia/cuda:11.3.1-cudnn8-runtime-ubuntu20.04的Docker镜像中安装Python3.11时遇到html5lib错误

0 投票
1 回答
63 浏览
提问于 2025-04-13 18:27

我正在使用这个Dockerfile:

FROM nvidia/cuda:11.3.1-cudnn8-runtime-ubuntu20.04
ENV DEBIAN_FRONTEND=noninteractive

# the following line is needed in order for the build to succeed due to some outdated stuff in the docker image
RUN apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/3bf863cc.pub

# Update package lists and install necessary tools
RUN apt-get update && \
    apt-get install -y software-properties-common

# Add deadsnakes PPA to get Python 3.11
RUN add-apt-repository ppa:deadsnakes/ppa

RUN apt update --fix-missing && \
        apt install python3.11 python3.11-distutils -y && \
        apt install python3-pip -y && \
        ln -sf /usr/bin/python3.11 /usr/bin/python && \
        ln -sf /usr/bin/pip3 /usr/bin/pip

# install latest pip
RUN curl -sS https://bootstrap.pypa.io/get-pip.py | python3.11

RUN apt-get update -y && apt-get install -y --no-install-recommends build-essential gcc \
                                        libsndfile1

ARG UNAME=user
ARG UID=1000
ARG GID=1000
RUN groupadd -g $GID -o $UNAME
RUN useradd -m -u $UID -g $GID -o -s /bin/bash $UNAME
USER $UNAME

COPY requirements.txt /tmp/requirements.txt
RUN python -m pip install --user setuptools wheel
RUN python -m pip install --user --no-cache-dir -r /tmp/requirements.txt -f https://download.pytorch.org/whl/cu113/torch_stable.html

正如评论中提到的,我添加了deadsnakes PPA来获取Python 3.11。可是我一直遇到这个错误:

File "/usr/lib/python3/dist-packages/pip/_internal/index/collector.py", line 12, in <module>
0.929     from pip._vendor import html5lib, requests
0.929 ImportError: cannot import name 'html5lib' from 'pip._vendor' (/usr/lib/python3/dist-packages/pip/_vendor/__init__.py)

我按照这个回答的建议,使用get-pip.py来安装pip,但还是没有成功。

1 个回答

0

我之前在我的容器里安装Python3.10时遇到了一些问题,最后我搞定了这个设置。虽然我不记得当时具体是什么错误,但也许这里的内容对你有帮助。

# Installing python 3.10
    docker exec -it $CONTAINER_NAME bash -c "
    apt-get update \
    && apt-get install -y software-properties-common \
    && add-apt-repository -y ppa:deadsnakes/ppa \
    && apt-get update \
    && apt install -y python3.10
    "

# Force upgrade to python3.10
    docker exec -it $CONTAINER_NAME bash -c "
    update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.8 1 \
    && update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.10 2 \
    && update-alternatives --set python3 /usr/bin/python3.10 \
    && apt-get install -y python3.10-distutils \
    && curl -sS https://bootstrap.pypa.io/get-pip.py | python3.10
    "

撰写回答