在 gcloud 上部署烧瓶应用程序时出现“找不到 CMAKE_CXX_COMPILER”错误

Posted

技术标签:

【中文标题】在 gcloud 上部署烧瓶应用程序时出现“找不到 CMAKE_CXX_COMPILER”错误【英文标题】:"No CMAKE_CXX_COMPILER could be found" errror while deploying flask app on gcloud 【发布时间】:2021-12-20 05:34:33 【问题描述】:

我有一个在谷歌云上部署的烧瓶应用程序。使用需要 Cmake 的库“face_recognition”的应用程序。我通过在 DockerFile 中运行命令来安装 CMake,但出现错误。我不知道这是什么意思。

这是我的 Dockerfile

# Use the official lightweight Python image.
# https://hub.docker.com/_/python
FROM python:3.9-slim

# Allow statements and log messages to immediately appear in the Knative logs
ENV PYTHONUNBUFFERED True

# Copy local code to the container image.
ENV APP_HOME /app
WORKDIR $APP_HOME
COPY . ./

# Install production dependencies.
RUN apt-get update && apt-get install -y cmake
RUN pip install --no-cache-dir -r requirements.txt
RUN pip install gunicorn

# Run the web service on container startup. Here we use the gunicorn
# webserver, with one worker process and 8 threads.
# For environments with multiple CPU cores, increase the number of workers
# to be equal to the cores available.
# Timeout is set to 0 to disable the timeouts of the workers to allow Cloud Run to handle instance scaling.
CMD exec gunicorn --bind :$PORT --workers 1 --threads 8 --timeout 0 main:app

这是错误

CMake Error at CMakeLists.txt:14 (project):
      No CMAKE_CXX_COMPILER could be found.
    
      Tell CMake where to find the compiler by setting either the environment
      variable "CXX" or the CMake cache entry CMAKE_CXX_COMPILER to the full path
      to the compiler, or to the compiler name if it is in the PATH.
    
    
    -- Configuring incomplete, errors occurred!
    See also "/tmp/pip-install-2m1peq73/dlib_d6f82528b68745578021b2f234f89d7c/build/temp.linux-x86_64-3.9/CMakeFiles/CMakeOutput.log".
    See also "/tmp/pip-install-2m1peq73/dlib_d6f82528b68745578021b2f234f89d7c/build/temp.linux-x86_64-3.9/CMakeFiles/CMakeError.log".
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-install-2m1peq73/dlib_d6f82528b68745578021b2f234f89d7c/setup.py", line 222, in <module>
        setup(
      File "/usr/local/lib/python3.9/site-packages/setuptools/__init__.py", line 153, in setup
        return distutils.core.setup(**attrs)
      File "/usr/local/lib/python3.9/distutils/core.py", line 148, in setup
        dist.run_commands()
      File "/usr/local/lib/python3.9/distutils/dist.py", line 966, in run_commands
        self.run_command(cmd)
      File "/usr/local/lib/python3.9/distutils/dist.py", line 985, in run_command
        cmd_obj.run()
      File "/usr/local/lib/python3.9/site-packages/setuptools/command/install.py", line 61, in run
        return orig.install.run(self)
      File "/usr/local/lib/python3.9/distutils/command/install.py", line 546, in run
        self.run_command('build')
      File "/usr/local/lib/python3.9/distutils/cmd.py", line 313, in run_command
        self.distribution.run_command(command)
      File "/usr/local/lib/python3.9/distutils/dist.py", line 985, in run_command
        cmd_obj.run()
      File "/usr/local/lib/python3.9/distutils/command/build.py", line 135, in run
        self.run_command(cmd_name)
      File "/usr/local/lib/python3.9/distutils/cmd.py", line 313, in run_command
        self.distribution.run_command(command)
      File "/usr/local/lib/python3.9/distutils/dist.py", line 985, in run_command
        cmd_obj.run()
      File "/tmp/pip-install-2m1peq73/dlib_d6f82528b68745578021b2f234f89d7c/setup.py", line 134, in run
        self.build_extension(ext)
      File "/tmp/pip-install-2m1peq73/dlib_d6f82528b68745578021b2f234f89d7c/setup.py", line 171, in build_extension
        subprocess.check_call(cmake_setup, cwd=build_folder)
      File "/usr/local/lib/python3.9/subprocess.py", line 373, in check_call
        raise CalledProcessError(retcode, cmd)

【问题讨论】:

您好,请尝试在您的 Dockerfile 中使用 sudo apt-get install build-essential,如 here 所述。 【参考方案1】:

容器基础 python:3.9-slim 非常精简。如果您的应用程序需要 CMake,这通常也意味着 gcc 编译器, 你至少有两个选择:

    使用功能更丰富的基础容器,例如 debian:buster 选择一个已经配置了这些工具的容器。

构建基础容器的示例 Dockerfile:

FROM debian:buster
RUN apt update && apt install -y gcc clang clang-tools cmake python3

然后,您可以将该容器用作未来容器的基础,或修改 Dockerfile 以包含您的应用程序。

Docker debian:buster

【讨论】:

以上是关于在 gcloud 上部署烧瓶应用程序时出现“找不到 CMAKE_CXX_COMPILER”错误的主要内容,如果未能解决你的问题,请参考以下文章

在 Windows 上通过 Apache Lounge 部署烧瓶应用程序时出现内部服务器错误

使用 CLI 将烧瓶应用程序部署到弹性 beanstalk 时出现 502 错误

使用 ngrok 部署烧瓶应用程序时出现错误索引

Flask“(”使用gunicorn时出现意外错误

尝试访问部署在 Netlify 上的站点时出现“找不到页面”

网站部署到 IIS 并连接到 SQL Server 2012 时出现问题,出现找不到网络错误