docker中的Python包含

2024-05-14 10:08:52 发布

您现在位置:Python中文网/ 问答频道 /正文

我是新来的码头工人,所以我很抱歉这么简单的问题。

我正在构建一个docker容器,它构建在一个基于ubuntu:vivid image的图像之上。 在容器中执行脚本时,出现错误:

exec: "python": executable file not found in $PATH

我该怎么解决? 当我试图在Docker文件中运行apt-get install python时:

FROM my_image # based on ubuntu:vivid

RUN apt-get update && \
    apt-get install -y python3

ENV PATH /:$PATH

COPY file.py /

CMD ["python", "file.py", "-h"]

我得到:

WARNING: The following packages cannot be authenticated!
  libexpat1 libffi6 libmagic1 libmpdec2 libssl1.0.0 libpython3.4-minimal
  mime-support libsqlite3-0 libpython3.4-stdlib python3.4-minimal
  python3-minimal python3.4 libpython3-stdlib dh-python python3 file
E: There are problems and -y was used without --force-yes
The command '/bin/sh -c apt-get update &&   apt-get install -y python3' returned a non-zero code: 100
make: *** [image] Error 1

编辑:添加的Dockerfile内容


Tags: installthepathpyimagegetubuntuapt
2条回答

您正在安装python3,然后使用python的可执行文件,我遇到了同样的问题,我已经使用python3解决了这个问题。

尝试更改Dockerfile的最后一行:

而不是 CMD ["python", "file.py", "-h"]

尝试: CMD ["python3", "file.py", "-h"]

对于某些Linux发行版,您也有类似的问题:“Why am I getting authentication errors for packages from an Ubuntu repository?

在所有情况下,安装新软件包的通常命令顺序是:

RUN apt-get update -yq && apt-get install -yqq \
    git \
    python \
    ...

OP Ela报告in the comments

RUN apt-get update -y && apt-get install -y --force-yes \
    git \
    python \
    ...

相关问题 更多 >

    热门问题