在Docker文件中安装python软件包 [英] Install python package in docker file

查看:520
本文介绍了在Docker文件中安装python软件包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的docker文件中,我想安装med2image python软件包( https://github.com/FNNDSC/med2image )。我使用以下代码:

In my docker file, I want to install med2image python package (https://github.com/FNNDSC/med2image). I use the following code:

FROM ubuntu:16.04
RUN apt-get update && apt-get install -y --no-install-recommends \
    python3.5 \
    python3-pip \
    && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
RUN pip install nibabel pydicom matplotlib pillow
RUN pip install med2image

但是当我要构建图像时出现以下错误:

But I get the following error when I want to build the image:

Downloading https://files.pythonhosted.org/packages/6f/e5/948b023c7feb72adf7dfb26d90a13c838737bbf52be704f5ddd0878e3264/med2image-1.1.2.tar.gz
Complete output from command python setup.py egg_info:
Sorry, only Python 3.5+ is supported.

----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in  /tmp/pip-install-FnNb_S/med2image/
The command '/bin/sh -c pip install med2image' returned a non-zero code: 1

我该怎么办?!

推荐答案

推荐的基本映像



正如我的评论中所建议的,您可以编写一个如下所示的Dockerfile:

Recommended base image

As suggested in my comment, you could write a Dockerfile that looks like:

FROM python:3

RUN pip install --upgrade pip && \
    pip install --no-cache-dir nibabel pydicom matplotlib pillow && \
    pip install --no-cache-dir med2image

CMD ["cat", "/etc/os-release"]

上面的命令示例可以在运行时确认( docker build --pull -t test。&& docker run- -rm -it测试),该映像基于GNU / Linux发行版 Debian稳定版。

And the command example above could confirm at runtime (docker build --pull -t test . && docker run --rm -it test) that this image is based on the GNU/Linux distribution "Debian stable".

最后给出一个全面的答案,请注意,有关Python依赖项的一个好的实践是在声明中指定它们 格式的文本文件(按字母顺序排列),因此对于您的示例,您可能需要编写以下文件:

Finally to give a comprehensive answer, note that a good practice regarding Python dependencies consists in specifying them in a declarative way in a dedicated text file (in alphabetical order) so that for your example, you may want to write the following file:


requirements.txt



matplotlib
med2image
nibabel
pillow
pydicom




并使用以下通用 Dockerfile



FROM python:3

WORKDIR /usr/src/app

COPY requirements.txt ./

RUN pip install --upgrade pip && \
    pip install --no-cache-dir -r requirements.txt

COPY . .

CMD [ "python", "./your-daemon-or-script.py" ]

更确切地说,这是Docker官方映像文档中建议的方法 python ,§。 如何使用此图像

To be more precise, this is the approach suggested in the documentation of the Docker official image python, §. How to use this image

这篇关于在Docker文件中安装python软件包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆