【发布时间】:2019-11-17 02:52:16
【问题描述】:
我正在尝试构建一个 docker 容器,使我能够运行需要 python torch 模块的代码。
我选择从pytorch/pytorch:latest 基础镜像开始我的镜像并手动添加一些必需的模块。构建、推送和拉取到远程服务器成功(至少没有错误消息)。
目前我的 Dockerfile 看起来像这样:
FROM pytorch/pytorch:latest
RUN apt-get update \
&& apt-get install -y \
libgl1-mesa-glx \
libx11-xcb1 \
&& apt-get clean all \
&& rm -r /var/lib/apt/lists/*
RUN /opt/conda/bin/conda install --yes \
astropy \
matplotlib \
pandas \
glob2 \
PIL \
scikit-learn \
scikit-image \
numpy
但是,在容器中运行我的 python 脚本时,我得到ImportError: No module named torch。这让我觉得很奇怪,因为它让我假设 pytorch 基础映像不包含 torch 模块...?
尽管如此,我还是尝试将 torch 添加到要在 Dockerfile 中安装的模块列表中,但是初始构建已经失败并出现错误消息 PackagesNotFoundError: The following packages are not available from current channels: - torch。不幸的是,遵循here 的建议对我没有帮助。
我很感激任何解释为什么在构建的容器中找不到 torch 模块,当然还有任何帮助来解决这个问题!谢谢!
【问题讨论】:
-
你试过了吗?
-
是的,我尝试了通过 pip 将 Torch 安装到容器中的方法,效果很好。但是,我需要它在图像中更易于访问,以便随机用户不必手动将 Torch 安装到每个启动的容器中
-
Sara 看到我的答案,torch 将成为您的 dockerfile 的一部分,例如 ` RUN /opt/conda/bin/conda install --yes \ astropy \ matplotlib \ pandas \ glob2 \ scikit-learn \ scikit -image\numpy\torch`
标签: python docker anaconda dockerfile pytorch