简体   繁体   English

Lambda docker base - 无法安装 matplotlib

[英]Lambda docker base - unable to install matplotlib

I'm using docker-backed lambdas with the AWS-provided base image for python3.8.我将 docker 支持的 lambda 与 AWS 提供的 python3.8 基础映像一起使用。

It looks like it tries to build matplotlib from scratch, then fails out with gcc related errors.看起来它试图从头开始构建 matplotlib,然后失败并出现 gcc 相关错误。

The repro is straightforward, just try to build the following Dockerfile:重现很简单,只需尝试构建以下 Dockerfile:

FROM amazon/aws-lambda-python:3.8
RUN yum -y install gcc
RUN pip3 install --upgrade pip
RUN pip3 install matplotlib

Error:错误:

#7 13.82     set build/lib.linux-x86_64-3.8/matplotlib/_version.py to '3.4.3'
#7 13.82     running build_ext
#7 13.82     creating tmp
#7 13.82     gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -I/var/lang/include/python3.8 -c /tmp/tmpjr1hj4f1.cpp -o tmp/tmpjr1hj4f1.o -fvisibility=hidden
#7 13.82     gcc: error trying to exec 'cc1plus': execvp: No such file or directory
#7 13.82     gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -I/var/lang/include/python3.8 -c /tmp/tmp74f416b5.cpp -o tmp/tmp74f416b5.o -fvisibility-inlines-hidden
#7 13.82     gcc: error trying to exec 'cc1plus': execvp: No such file or directory
#7 13.82     gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -I/var/lang/include/python3.8 -c /tmp/tmp19pyjmxw.cpp -o tmp/tmp19pyjmxw.o -flto
#7 13.82     gcc: error trying to exec 'cc1plus': execvp: No such file or directory
#7 13.82     Extracting /project/freetype/freetype2/2.6.1/freetype-2.6.1.tar.gz
#7 13.82     Building freetype in build/freetype-2.6.1
#7 13.82     GNU make (>= 3.80) or makepp (>= 1.19) is required to build FreeType2.
#7 13.82     Please try
#7 13.82     
#7 13.82       MAKE=<GNU make command name> ./configure
#7 13.82     
#7 13.82     or
#7 13.82     
#7 13.82       MAKE="makepp --norc-substitution" ./configure
#7 13.82     Traceback (most recent call last):
#7 13.82       File "<string>", line 1, in <module>
#7 13.82       File "/tmp/pip-install-v3njpp10/matplotlib_5bf0432199ce40b5a487eafc6a513cc3/setup.py", line 258, in <module>
#7 13.82         setup(  # Finally, pass this all along to distutils to do the heavy lifting.
#7 13.82       File "/var/lang/lib/python3.8/site-packages/setuptools/__init__.py", line 153, in setup
#7 13.82         return distutils.core.setup(**attrs)
#7 13.82       File "/var/lang/lib/python3.8/distutils/core.py", line 148, in setup
#7 13.82         dist.run_commands()
#7 13.82       File "/var/lang/lib/python3.8/distutils/dist.py", line 966, in run_commands
#7 13.82         self.run_command(cmd)
#7 13.82       File "/var/lang/lib/python3.8/distutils/dist.py", line 985, in run_command
#7 13.82         cmd_obj.run()
#7 13.82       File "/var/lang/lib/python3.8/site-packages/setuptools/command/install.py", line 61, in run
#7 13.82         return orig.install.run(self)
#7 13.82       File "/var/lang/lib/python3.8/distutils/command/install.py", line 545, in run
#7 13.82         self.run_command('build')
#7 13.82       File "/var/lang/lib/python3.8/distutils/cmd.py", line 313, in run_command
#7 13.82         self.distribution.run_command(command)
#7 13.82       File "/var/lang/lib/python3.8/distutils/dist.py", line 985, in run_command
#7 13.82         cmd_obj.run()
#7 13.82       File "/var/lang/lib/python3.8/distutils/command/build.py", line 135, in run
#7 13.82         self.run_command(cmd_name)
#7 13.82       File "/var/lang/lib/python3.8/distutils/cmd.py", line 313, in run_command
#7 13.82         self.distribution.run_command(command)
#7 13.82       File "/var/lang/lib/python3.8/distutils/dist.py", line 985, in run_command
#7 13.82         cmd_obj.run()
#7 13.82       File "/var/lang/lib/python3.8/site-packages/setuptools/command/build_ext.py", line 79, in run
#7 13.82         _build_ext.run(self)
#7 13.82       File "/var/lang/lib/python3.8/distutils/command/build_ext.py", line 340, in run
#7 13.82         self.build_extensions()
#7 13.82       File "/tmp/pip-install-v3njpp10/matplotlib_5bf0432199ce40b5a487eafc6a513cc3/setup.py", line 199, in build_extensions
#7 13.82         package.do_custom_build(env)
#7 13.82       File "/tmp/pip-install-v3njpp10/matplotlib_5bf0432199ce40b5a487eafc6a513cc3/setupext.py", line 596, in do_custom_build
#7 13.82         subprocess.check_call(
#7 13.82       File "/var/lang/lib/python3.8/subprocess.py", line 364, in check_call
#7 13.82         raise CalledProcessError(retcode, cmd)
#7 13.82     subprocess.CalledProcessError: Command '['./configure', '--with-zlib=no', '--with-bzip2=no', '--with-png=no', '--with-harfbuzz=no', '--enable-static', '--disable-shared']' returned non-zero exit status 1.
#7 13.82     ----------------------------------------
#7 13.83 ERROR: Command errored out with exit status 1: /var/lang/bin/python3.8 -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-v3njpp10/matplotlib_5bf0432199ce40b5a487eafc6a513cc3/setup.py'"'"'; __file__='"'"'/tmp/pip-install-v3njpp10/matplotlib_5bf0432199ce40b5a487eafc6a513cc3/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-vdv6xdpv/install-record.txt --single-version-externally-managed --compile --install-headers /var/lang/include/python3.8/matplotlib Check the logs for full command output.

It seems like you're getting an error because of missing binaries that are needed to compile matplotlib.由于缺少编译 matplotlib 所需的二进制文件,您似乎收到了错误消息。

Can you try to install the additional g++ package?您可以尝试安装额外的g++包吗? It is usualy named gcc-c++ with the yum installer so:它通常使用 yum 安装程序命名为gcc-c++ ,因此:

FROM amazon/aws-lambda-python:3.8
RUN yum -y install gcc gcc-c++
RUN pip3 install --upgrade pip
RUN pip3 install matplotlib

the fix was to add compiler tools to the docker image before trying to compile matplotlib.修复方法是在尝试编译 matplotlib 之前将编译器工具添加到 docker 映像。 I still don't know why this started failing for me, perhaps the base image was updated.我仍然不知道为什么这对我来说开始失败,可能是基本图像已更新。

RUN yum -y groups mark install "Development Tools" && yum -y groups mark convert "Development Tools" && yum -y group install "Development Tools"

I'm running into the same issue and I think it is matplotlib's fault.我遇到了同样的问题,我认为这是 matplotlib 的错。 They released a new version (3.4.3) 17h ago as of this writing.在撰写本文时,他们在 17 小时前发布了一个新版本 (3.4.3) For me setting the version to the previous minor release, ie matplotlib==3.4.2 fixes it.对我来说,将版本设置为之前的小版本,即matplotlib==3.4.2修复了它。

There were no issues until today with my lambda deployment and nothing in my code changed so I think it's something in the new release though I do not know what exactly.直到今天我的 lambda 部署都没有问题,我的代码中没有任何变化,所以我认为这是新版本中的一些东西,尽管我不知道究竟是什么。

I had the same problem and I was trying to install matplotlib in a docker container using an alpine image.我遇到了同样的问题,我试图使用 alpine 图像在 docker 容器中安装 matplotlib。 For me the fix was the same as it was for @alex9311, but since I am on a docker alpine build, I was adding the following line to my image:对我来说,修复与@alex9311 的修复相同,但由于我使用的是 docker alpine 构建,因此我将以下行添加到我的图像中:

RUN apk update && apk add --no-cache build-base

I hope this helps.我希望这有帮助。 Only adding it as an answer so it doesn't get overlooked when it might help.仅将其添加为答案,以便在它可能有帮助时不会被忽视。

I was able to fix the problem by installing "make".我能够通过安装“make”来解决这个问题。 In the error logs posted in the question there is a statement在问题中发布的错误日志中有一个声明

GNU make (>= 3.80) or makepp (>= 1.19) is required to build FreeType2.

This is the cause of the matplotlib installation failure.这就是matplotlib安装失败的原因。 The cause of the error is that the docker image is missing an installation of GNU make.错误的原因是 docker 镜像缺少 GNU make 的安装。 The accepted answer installs all the packages in the "Development Tools" group (which includes make) which is not necessary.接受的答案会在“开发工具”组(包括 make)中安装所有不必要的包。 It will increase the docker image size which can be avoided by installing only "make".它会增加 docker 镜像的大小,这可以通过只安装“make”来避免。

FROM amazon/aws-lambda-python:3.8
RUN yum -y install gcc gcc-c++ make
RUN pip3 install --upgrade pip
RUN pip3 install matplotlib

The matplotlib installation was successful on installing make before installing matplotlib在安装matplotlib之前安装make时matplotlib安装成功

Changing the version as Daniel suggested also worked for me.按照丹尼尔的建议更改版本也对我有用。 matplotlib==3.5.1 in my case worked. matplotlib==3.5.1在我的案例中有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM