在 Dockerfile 中安装 pandas

新手上路,请多包涵

我正在尝试创建一个 Docker 映像。 Dockerfile 如下:

 # Use the official Python 3.6.5 image
FROM python:3.6.5-alpine3.7

# Set the working directory to /app
WORKDIR /app

# Get the
COPY requirements.txt /app
RUN pip3 install --no-cache-dir -r requirements.txt

# Configuring access to Jupyter
RUN mkdir /notebooks
RUN jupyter notebook --no-browser --ip 0.0.0.0 --port 8888 /notebooks

requirements.txt 文件是:

 jupyter
numpy==1.14.3
pandas==0.23.0rc2
scipy==1.0.1
scikit-learn==0.19.1
pillow==5.1.1
matplotlib==2.2.2
seaborn==0.8.1

运行命令 docker build -t standard . 在 docker 尝试安装 pandas 时给我一个错误。错误如下:

 Collecting pandas==0.23.0rc2 (from -r requirements.txt (line 3))
  Downloading https://files.pythonhosted.org/packages/46/5c/a883712dad8484ef907a2f42992b122acf2bcecbb5c2aa751d1033908502/pandas-0.23.0rc2.tar.gz (12.5MB)
    Complete output from command python setup.py egg_info:
    /bin/sh: svnversion: not found
    /bin/sh: svnversion: not found
    non-existing path in 'numpy/distutils': 'site.cfg'
    Could not locate executable gfortran
    ... (loads of other stuff)
    Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-install-xb6f6a5o/pandas/
The command '/bin/sh -c pip3 install --no-cache-dir -r requirements.txt' returned a non-zero code: 1

当我尝试安装较低版本的 pandas==0.22.0 时,出现以下错误:

 Step 5/7 : RUN pip3 install --no-cache-dir -r requirements.txt
 ---> Running in 5810ea896689
Collecting jupyter (from -r requirements.txt (line 1))
  Downloading https://files.pythonhosted.org/packages/83/df/0f5dd132200728a86190397e1ea87cd76244e42d39ec5e88efd25b2abd7e/jupyter-1.0.0-py2.py3-none-any.whl
Collecting numpy==1.14.3 (from -r requirements.txt (line 2))
  Downloading https://files.pythonhosted.org/packages/b0/2b/497c2bb7c660b2606d4a96e2035e92554429e139c6c71cdff67af66b58d2/numpy-1.14.3.zip (4.9MB)
Collecting pandas==0.22.0 (from -r requirements.txt (line 3))
  Downloading https://files.pythonhosted.org/packages/08/01/803834bc8a4e708aedebb133095a88a4dad9f45bbaf5ad777d2bea543c7e/pandas-0.22.0.tar.gz (11.3MB)
  Could not find a version that satisfies the requirement Cython (from versions: )
No matching distribution found for Cython
The command '/bin/sh -c pip3 install --no-cache-dir -r requirements.txt' returned a non-zero code: 1

我还尝试在 pandas 之前安装 Cyphon 和 setuptools,但它在 pip3 install pandas 行给出了相同的 No matching distribution found for Cython 错误。

我怎么能安装熊猫。

原文由 ccasimiro9444 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 1.5k
2 个回答

我现在可以创建 Docker 镜像了。 FROM python:3.6.5-alpine3.7 和 pandas 之间一定存在一些版本不兼容问题。我将 Python 版本更改为 FROM python:3 ,然后它工作正常(还必须将 pillow 版本降级为 5.1.0 )。

原文由 ccasimiro9444 发布,翻译遵循 CC BY-SA 4.0 许可协议

我意识到这个问题已经得到回答,但我最近遇到了一个类似的问题,即 numpy 和 pandas 依赖于一个 dockerized 项目。话虽这么说,但我希望这对将来的某个人有好处。

我的解决方案:

正如 Aviv Sela 所指出的,Alpine 默认不包含构建工具,需要通过 Dockerfile 添加。因此,请参阅下面我的 Dockerfile,其中包含 numpy 和 pandas 成功安装在容器的 Alpine 上所需的构建包。

 FROM python:3.6-alpine3.7

RUN apk add --no-cache --update \
    python3 python3-dev gcc \
    gfortran musl-dev g++ \
    libffi-dev openssl-dev \
    libxml2 libxml2-dev \
    libxslt libxslt-dev \
    libjpeg-turbo-dev zlib-dev

RUN pip install --upgrade pip

ADD requirements.txt .
RUN pip install -r requirements.txt

要求.txt

 numpy==1.17.1
pandas==0.25.1

编辑:

在升级 pip RUN 命令之前,将以下内容(下面的代码片段)添加到 Dockerfile。正如 Bishwas Mishra 在评论中指出的那样,这对于成功安装 pandas 至关重要。

 RUN pip install --upgrade cython

原文由 Kevin Smith 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题