1

我正在使用 docker 支持的 lambdas 和 AWS 为 python3.8 提供的基本映像。

看起来它试图从头开始构建 matplotlib,然后因 gcc 相关错误而失败。

复制很简单,只需尝试构建以下 Dockerfile:

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

错误:

#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.
4

5 回答 5

2

由于缺少编译 matplotlib 所需的二进制文件,您似乎遇到了错误。

您可以尝试安装附加g++软件包吗?它通常以gcc-c++yum 安装程序命名,因此:

FROM amazon/aws-lambda-python:3.8
RUN yum -y install gcc gcc-c++
RUN pip3 install --upgrade pip
RUN pip3 install matplotlib
于 2021-08-13T08:46:35.477 回答
1

解决方法是在尝试编译 matplotlib 之前将编译器工具添加到 docker 映像。我仍然不知道为什么这对我来说开始失败,也许基础图像已更新。

RUN yum -y groups mark install "Development Tools" && yum -y groups mark convert "Development Tools" && yum -y group install "Development Tools"
于 2021-08-13T17:22:30.960 回答
1

我遇到了同样的问题,我认为这是 matplotlib 的错。在撰写本文时,他们在 17 小时前发布了新版本 (3.4.3) 。对我来说,将版本设置为以前的次要版本,即matplotlib==3.4.2修复它。

直到今天,我的 lambda 部署都没有问题,我的代码没有任何变化,所以我认为这是新版本中的一些东西,尽管我不知道具体是什么。

于 2021-08-13T20:50:53.920 回答
1

我遇到了同样的问题,我试图使用 alpine 图像在 docker 容器中安装 matplotlib。对我来说,修复与 @alex9311 的修复相同,但由于我使用的是 docker alpine 构建,因此我将以下行添加到我的图像中:

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

我希望这有帮助。仅将其添加为答案,以便在可能有帮助时不会被忽视。

于 2021-09-08T18:00:15.537 回答
0

我能够通过安装“make”来解决这个问题。在问题中发布的错误日志中有一个声明

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

这是matplotlib安装失败的原因。错误的原因是 docker 镜像缺少 GNU make 的安装。接受的答案安装了“开发工具”组(包括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

在安装 matplotlib 之前安装 make 时 matplotlib 安装成功

于 2021-11-23T17:30:01.413 回答