You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Dockerfile安装Python包Ta-Lib失败,求助解决方案

在Cloud Run的Dockerfile中安装Python Ta-Lib包失败,求解决方法

我尝试在Cloud Run中通过Dockerfile安装Python的Ta-Lib包时遭遇编译错误,核心问题是找不到ta-lib/ta_defs.h头文件,导致pip无法构建ta-lib的wheel包。以下是完整报错信息、我的requirements.txt和Dockerfile内容,恳请有成功经验的人提供解决方案。

完整报错信息

error: subprocess-exited-with-error
  
  × Building wheel for ta-lib (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [27 lines of output]
      <string>:77: UserWarning: Cannot find ta-lib library, installation may fail.
      running bdist_wheel
      running build
      running build_py
      creating build
      creating build/lib.linux-x86_64-cpython-310
      creating build/lib.linux-x86_64-cpython-310/talib
      copying talib/test_polars.py -> build/lib.linux-x86_64-cpython-310/talib
      copying talib/test_pandas.py -> build/lib.linux-x86_64-cpython-310/talib
      copying talib/__init__.py -> build/lib.linux-x86_64-cpython-310/talib
      copying talib/test_stream.py -> build/lib.linux-x86_64-cpython-310/talib
      copying talib/stream.py -> build/lib.linux-x86_64-cpython-310/talib
      copying talib/abstract.py -> build/lib.linux-x86_64-cpython-310/talib
      copying talib/deprecated.py -> build/lib.linux-x86_64-cpython-310/talib
      copying talib/test_func.py -> build/lib.linux-x86_64-cpython-310/talib
      copying talib/test_abstract.py -> build/lib.linux-x86_64-cpython-310/talib
      copying talib/test_data.py -> build/lib.linux-x86_64-cpython-310/talib
      running build_ext
      building 'talib._ta_lib' extension
      creating build/temp.linux-x86_64-cpython-310
      creating build/temp.linux-x86_64-cpython-310/talib
      gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -I/usr/include -I/usr/local/include -I/opt/include -I/opt/local/include -I/opt/homebrew/include -I/opt/homebrew/opt/ta-lib/include -I/tmp/pip-build-env-yj8q5fu_/normal/lib/python3.10/site-packages/numpy/core/include -I/usr/local/include/python3.10 -c talib/_ta_lib.c -o build/temp.linux-x86_64-cpython-310/talib/_ta_lib.o
      talib/_ta_lib.c:747:10: fatal error: ta-lib/ta_defs.h: No such file or directory
        747 | #include "ta-lib/ta_defs.h"
            |          ^~~~~~~~~~~~~~~~~~
      compilation terminated.
      error: command '/usr/bin/gcc' failed with exit code 1
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for ta-lib
Successfully built websocket
Failed to build ta-lib
ERROR: Could not build wheels for ta-lib, which is required to install pyproject.toml-based projects

[notice] A new release of pip available: 22.2.2 -> 22.3.1
[notice] To update, run: pip install --upgrade pip
The command '/bin/sh -c pip install --no-cache-dir -r requirements.txt' returned a non-zero code: 1
ERROR
ERROR: build step 0 "gcr.io/cloud-builders/docker" failed: step exited with non-zero status: 1

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

BUILD FAILURE: Build step failure: build step 0 "gcr.io/cloud-builders/docker" failed: step exited with non-zero status: 1
ERROR: (gcloud.builds.submit) build 8c54cd65-f189-476a-8bd9-f7fe7b428bfe completed with status "FAILURE"

requirements.txt内容

Flask==2.1.0
gunicorn==20.1.0
websocket
pandas
numpy
ta-lib

Dockerfile内容

FROM python:3.10-slim

ENV PYTHONUNBUFFERED True

# Copy local code to the container image.
WORKDIR /var/www/html
COPY . /var/www/html/

# Install production dependencies.
RUN pip install --no-cache-dir -r requirements.txt

CMD exec gunicorn --bind :$PORT --workers 1 --threads 8 --timeout 0 main:app

内容的提问来源于stack exchange,提问作者Steeve

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.09 07:35:28