为什么在 Alpine Linux 上安装 Pandas 需要很长时间

2024-02-11

我注意到,使用基本操作系统 Alpine 与 CentOS 或 Debian 在 Docker 容器中安装 Pandas 和 Numpy(它的依赖项)需要更长的时间。我在下面创建了一个小测试来演示时差。除了 Alpine 需要几秒钟更新和下载构建依赖项来安装 Pandas 和 Numpy 之外,为什么 setup.py 花费的时间比 Debian 安装多大约 70 倍?

有没有什么方法可以使用 Alpine 作为基础镜像来加速安装,或者是否有另一个与 Alpine 大小相当的基础镜像更适合 Pandas 和 Numpy 等软件包?

Dockerfile.debian

FROM python:3.6.4-slim-jessie

RUN pip install pandas

使用 Pandas 和 Numpy 构建 Debian 映像:

[PandasDockerTest] time docker build -t debian-pandas -f Dockerfile.debian . --no-cache
    Sending build context to Docker daemon  3.072kB
    Step 1/2 : FROM python:3.6.4-slim-jessie
     ---> 43431c5410f3
    Step 2/2 : RUN pip install pandas
     ---> Running in 2e4c030f8051
    Collecting pandas
      Downloading pandas-0.22.0-cp36-cp36m-manylinux1_x86_64.whl (26.2MB)
    Collecting numpy>=1.9.0 (from pandas)
      Downloading numpy-1.14.1-cp36-cp36m-manylinux1_x86_64.whl (12.2MB)
    Collecting pytz>=2011k (from pandas)
      Downloading pytz-2018.3-py2.py3-none-any.whl (509kB)
    Collecting python-dateutil>=2 (from pandas)
      Downloading python_dateutil-2.6.1-py2.py3-none-any.whl (194kB)
    Collecting six>=1.5 (from python-dateutil>=2->pandas)
      Downloading six-1.11.0-py2.py3-none-any.whl
    Installing collected packages: numpy, pytz, six, python-dateutil, pandas
    Successfully installed numpy-1.14.1 pandas-0.22.0 python-dateutil-2.6.1 pytz-2018.3 six-1.11.0
    Removing intermediate container 2e4c030f8051
     ---> a71e1c314897
    Successfully built a71e1c314897
    Successfully tagged debian-pandas:latest
    docker build -t debian-pandas -f Dockerfile.debian . --no-cache  0.07s user 0.06s system 0% cpu 13.605 total

Dockerfile.alpine

FROM python:3.6.4-alpine3.7

RUN apk --update add --no-cache g++

RUN pip install pandas

使用 Pandas 和 Numpy 构建 Alpine 图像:

[PandasDockerTest] time docker build -t alpine-pandas -f Dockerfile.alpine . --no-cache
Sending build context to Docker daemon   16.9kB
Step 1/3 : FROM python:3.6.4-alpine3.7
 ---> 4b00a94b6f26
Step 2/3 : RUN apk --update add --no-cache g++
 ---> Running in 4b0c32551e3f
fetch http://dl-cdn.alpinelinux.org/alpine/v3.7/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.7/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.7/community/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.7/community/x86_64/APKINDEX.tar.gz
(1/17) Upgrading musl (1.1.18-r2 -> 1.1.18-r3)
(2/17) Installing libgcc (6.4.0-r5)
(3/17) Installing libstdc++ (6.4.0-r5)
(4/17) Installing binutils-libs (2.28-r3)
(5/17) Installing binutils (2.28-r3)
(6/17) Installing gmp (6.1.2-r1)
(7/17) Installing isl (0.18-r0)
(8/17) Installing libgomp (6.4.0-r5)
(9/17) Installing libatomic (6.4.0-r5)
(10/17) Installing pkgconf (1.3.10-r0)
(11/17) Installing mpfr3 (3.1.5-r1)
(12/17) Installing mpc1 (1.0.3-r1)
(13/17) Installing gcc (6.4.0-r5)
(14/17) Installing musl-dev (1.1.18-r3)
(15/17) Installing libc-dev (0.7.1-r0)
(16/17) Installing g++ (6.4.0-r5)
(17/17) Upgrading musl-utils (1.1.18-r2 -> 1.1.18-r3)
Executing busybox-1.27.2-r7.trigger
OK: 184 MiB in 50 packages
Removing intermediate container 4b0c32551e3f
 ---> be26c3bf4e42
Step 3/3 : RUN pip install pandas
 ---> Running in 36f6024e5e2d
Collecting pandas
  Downloading pandas-0.22.0.tar.gz (11.3MB)
Collecting python-dateutil>=2 (from pandas)
  Downloading python_dateutil-2.6.1-py2.py3-none-any.whl (194kB)
Collecting pytz>=2011k (from pandas)
  Downloading pytz-2018.3-py2.py3-none-any.whl (509kB)
Collecting numpy>=1.9.0 (from pandas)
  Downloading numpy-1.14.1.zip (4.9MB)
Collecting six>=1.5 (from python-dateutil>=2->pandas)
  Downloading six-1.11.0-py2.py3-none-any.whl
Building wheels for collected packages: pandas, numpy
  Running setup.py bdist_wheel for pandas: started
  Running setup.py bdist_wheel for pandas: still running...
  Running setup.py bdist_wheel for pandas: still running...
  Running setup.py bdist_wheel for pandas: still running...
  Running setup.py bdist_wheel for pandas: still running...
  Running setup.py bdist_wheel for pandas: still running...
  Running setup.py bdist_wheel for pandas: still running...
  Running setup.py bdist_wheel for pandas: finished with status 'done'
  Stored in directory: /root/.cache/pip/wheels/e8/ed/46/0596b51014f3cc49259e52dff9824e1c6fe352048a2656fc92
  Running setup.py bdist_wheel for numpy: started
  Running setup.py bdist_wheel for numpy: still running...
  Running setup.py bdist_wheel for numpy: still running...
  Running setup.py bdist_wheel for numpy: still running...
  Running setup.py bdist_wheel for numpy: finished with status 'done'
  Stored in directory: /root/.cache/pip/wheels/9d/cd/e1/4d418b16ea662e512349ef193ed9d9ff473af715110798c984
Successfully built pandas numpy
Installing collected packages: six, python-dateutil, pytz, numpy, pandas
Successfully installed numpy-1.14.1 pandas-0.22.0 python-dateutil-2.6.1 pytz-2018.3 six-1.11.0
Removing intermediate container 36f6024e5e2d
 ---> a93c59e6a106
Successfully built a93c59e6a106
Successfully tagged alpine-pandas:latest
docker build -t alpine-pandas -f Dockerfile.alpine . --no-cache  0.54s user 0.33s system 0% cpu 16:08.47 total

仅使用基于 Debian 的映像python pip安装软件包.whl format:

  Downloading pandas-0.22.0-cp36-cp36m-manylinux1_x86_64.whl (26.2MB)
  Downloading numpy-1.14.1-cp36-cp36m-manylinux1_x86_64.whl (12.2MB)

WHL 格式被开发为一种比每次从源代码重新构建更快、更可靠的安装 Python 软件的方法。 WHL 文件只需移动到目标系统上的正确位置即可安装,而源发行版则需要在安装前执行构建步骤。

轮组pandas and numpy基于Alpine平台的镜像不支持。这就是为什么当我们使用它们安装时python pip在构建过程中,我们总是从 alpine 中的源文件编译它们:

  Downloading pandas-0.22.0.tar.gz (11.3MB)
  Downloading numpy-1.14.1.zip (4.9MB)

在镜像构建过程中我们可以看到容器内部如下:

/ # ps aux
PID   USER     TIME   COMMAND
    1 root       0:00 /bin/sh -c pip install pandas
    7 root       0:04 {pip} /usr/local/bin/python /usr/local/bin/pip install pandas
   21 root       0:07 /usr/local/bin/python -c import setuptools, tokenize;__file__='/tmp/pip-build-en29h0ak/pandas/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n
  496 root       0:00 sh
  660 root       0:00 /bin/sh -c gcc -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -DTHREAD_STACK_SIZE=0x100000 -fPIC -Ibuild/src.linux-x86_64-3.6/numpy/core/src/pri
  661 root       0:00 gcc -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -DTHREAD_STACK_SIZE=0x100000 -fPIC -Ibuild/src.linux-x86_64-3.6/numpy/core/src/private -Inump
  662 root       0:00 /usr/libexec/gcc/x86_64-alpine-linux-musl/6.4.0/cc1 -quiet -I build/src.linux-x86_64-3.6/numpy/core/src/private -I numpy/core/include -I build/src.linux-x86_64-3.6/numpy/core/includ
  663 root       0:00 ps aux

如果我们修改Dockerfile一点:

FROM python:3.6.4-alpine3.7
RUN apk add --no-cache g++ wget
RUN wget https://pypi.python.org/packages/da/c6/0936bc5814b429fddb5d6252566fe73a3e40372e6ceaf87de3dec1326f28/pandas-0.22.0-cp36-cp36m-manylinux1_x86_64.whl
RUN pip install pandas-0.22.0-cp36-cp36m-manylinux1_x86_64.whl

我们得到以下错误:

Step 4/4 : RUN pip install pandas-0.22.0-cp36-cp36m-manylinux1_x86_64.whl
 ---> Running in 0faea63e2bda
pandas-0.22.0-cp36-cp36m-manylinux1_x86_64.whl is not a supported wheel on this platform.
The command '/bin/sh -c pip install pandas-0.22.0-cp36-cp36m-manylinux1_x86_64.whl' returned a non-zero code: 1

不幸的是,唯一的安装方法pandas在 Alpine 图像上,等待构建完成。

当然,如果你想使用 Alpine 图像pandas例如,在 CI 中,最好的方法是编译一次,将其推送到任何注册表,并将其用作满足您需求的基础映像。

EDIT:如果您想使用 Alpine 图像pandas你可以拉我的尼克格里格/高山熊猫 https://hub.docker.com/r/nickgryg/alpine-pandas/泊坞窗图像。这是一个预编译的Python图像pandas在Alpine平台上。它应该可以节省您的时间。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

为什么在 Alpine Linux 上安装 Pandas 需要很长时间 的相关文章

随机推荐

  • 我正在尝试创建一个可访问的
  • Spring MVC 与 hibernate Validator 来验证单个基本类型

    下面是我遇到问题的映射方法 无论我传递给它什么值 验证都会返回 通过验证 RequestMapping value test method RequestMethod POST ResponseBody public String getT
  • 网站不同部分使用不同的 SSL 证书

    我在 example com 上有一个网站 它从 s example com 亚马逊 Cloudfront 发行版 加载所有静态组件 现在我想让 example com 的一些页面使用 https 所以我想我应该为 example com
  • 了解 Kafka 主题和分区

    我开始学习卡夫卡 在阅读过程中 我想到了一些问题 当生产者生成消息时 它会指定topic它想要将消息发送到 是对的吗 它关心分区吗 当订阅者运行时 它是否指定其组ID 以便它可以成为同一主题或该组消费者感兴趣的多个主题的消费者集群的一部分
  • 使用 Jquery 将剪贴板图像复制到网页中

    我想将剪贴板图像复制到网页中 前任 用户单击打印屏幕按钮 打开网页 单击 CTRL V 图像将上传到网页 可以使用 jquery javascript 或 PHP 吗 在火狐浏览器中可以吗 提前致谢 恐怕不是 不是 您必须让用户将屏幕截图保
  • 在哪里更改oracle 11g中的NLS_DATE_FORMAT?

    我需要更改存储过程中的 NLS DATE FORMAT 似乎它是一个会话变量 我应该在哪里更改变量掩码 应该在全局声明中还是其他地方完成 我的意思是从前端 如果您想更改过程中的 NLS 参数 则可以使用DBMS SESSION SET NL
  • 元素“标题”出现次数太少,ASP.NET.MVC 母版页中出现 XHTML 验证警告

    我在 ASP NET MVC 母版页中收到以下 XHTML 验证警告 验证 XHTML 1 0 Transitional 元素 title 出现的次数太少 母版页的标题标签包含在 head 标签的 ContentPlaceHolder 中
  • NLTK数据安装问题

    我正在尝试在 Mac OSX 10 9 上安装 NLTK Data NLTK 3 0文档中提到 要设置的下载目录是 usr share nltk data 用于集中安装 但对于这条路径 我收到错误 OSError Errno 13 权限被拒
  • 运算符重载Python自定义类

    假设我想重载一个运算符 假设 现在 对于我创建的一些课程 class A object code here 进而 a A b A 我会做什么来定义 c a b 或类似的规定 注意 这个问题纯粹是理论上的 我可能会在某个时候使用它 只是目前不
  • C++:这个运算符^是什么? [复制]

    这个问题在这里已经有答案了 int main std string original Hello world std string decrypted std string encrypted char key x cout lt lt O
  • 使用 SqlConnection 和 VB.NET 创建 ASP.NET 聚合源

    这似乎是 Scott Mitchell 撰写的一篇很棒的文章 用于创建联合提要ASP NET 3 5 对我来说 问题是它使用 C 和 Linq 目前我对这两种语言不太熟悉 http dotnetslackers com articles a
  • Elastic Beanstalk 无法识别文件的绝对路径,返回 FileNotFoundError

    我正在使用 AWS Elastic Beanstalk 运行 Flask 应用程序 应用程序部署成功 但我的代码中有一个任务使用 pandasread csv从 csv 文件中提取数据 代码行是 form1 pd read csv opt
  • 为什么 numberOfSectionsInTableView 在 UITableViewController 中被调用两次?

    是否还有其他原因 除了调用 reloadData 为什么 numberOfSectionsInTableView 被调用两次 我进行了调试 发现在初始启动期间 当没有调用自定义 reloadData 语句时 它会被调用两次 我已经使用 IB
  • 部署 MVC,无需关闭整个站点

    假设我想对我的 MVC 项目的一个视图中的某些内容进行更改 一些非常简单的事情 比如删除一个句子或添加一个句号或其他东西 因此 据我所知 我必须重新发布整个网站 然后删除整个网站并用新发布的集合替换它 我想知道是否有一种方法 如果我对单个页
  • 如何从 Ubuntu 19.10 卸载 python 3.7?

    我在用着Ubuntu 19 10 其中有python的版本3 7 发布后python 3 8 我已经安装了 现在我想卸载python 3 7这样每当我打电话时python3在我的终端中 它总是会调用python3 8 您不需要为此卸载旧版本
  • 如何在不绑定V​​iewModel(MVVM)中UI的情况下使用android导航?

    我正在使用在 Google I O 2018 上展示的 Android 导航 似乎我可以通过绑定到某些视图或使用NavHost从 Fragment 中获取它 但我需要的是根据几个条件从我的第一个片段导航到 ViewModel 的另一个特定视
  • if else 和 #if #else #endif 之间的区别

    我很困惑if else and if else endif结构体 它们之间有什么区别 我应该在哪些具体情况下使用它们 if and else 条件在运行时评估 if else由预处理器在编译之前进行评估
  • 为什么“a”标签需要“tabindex=0”?

    我正在开发一个网络应用程序 其中一个重复的应用程序a当我通过 Tab 键浏览页面时 锚点 元素没有获得键盘焦点 仅当我添加tabindex 0我可以点击它吗 虽然我的目标是使焦点可见 但我正在使用 jQuery 片段确定元素是否获得焦点 W
  • 是否有一种简洁的方法在 Google Guava 中为 InputStream 创建 InputSupplier?

    Google Guava 中有一些工厂方法来创建 InputSuppliers 例如从一个byte ByteStreams newInputStreamSupplier bytes 或者从一个File Files newInputStrea
  • 为什么在 Alpine Linux 上安装 Pandas 需要很长时间

    我注意到 使用基本操作系统 Alpine 与 CentOS 或 Debian 在 Docker 容器中安装 Pandas 和 Numpy 它的依赖项 需要更长的时间 我在下面创建了一个小测试来演示时差 除了 Alpine 需要几秒钟更新和下