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

Docker部署DRF项目安装ruamel.yaml.clib==0.2.6报错如何解决

Django REST Framework项目Docker部署ruamel.yaml.clib安装报错解决

问题场景

对DRF项目做Docker容器化部署时,requirements.txt中ruamel.yaml.clib==0.2.6依赖安装失败,其余依赖均可正常安装,且该依赖在非Docker环境下可正常安装。

报错信息

#11 208.5 Collecting ruamel.yaml.clib==0.2.6
#11 208.7   Downloading ruamel.yaml.clib-0.2.6.tar.gz (180 kB)
#11 217.8     ERROR: Command errored out with exit status 1:
#11 217.8      command: /usr/local/bin/python -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-b8oectgw/ruamel-yaml-clib_517e9b3f18a94ebea71ec88fbaece43a/setup.py'"'"'; __file__='"'"'/tmp/pip-install-b8oectgw/ruamel-yaml-clib_517e9b3f18a94ebea71ec88fbaece43a/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'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-n2gr5j35
#11 217.8          cwd: /tmp/pip-install-b8oectgw/ruamel-yaml-clib_517e9b3f18a94ebea71ec88fbaece43a/
#11 217.8     Complete output (3 lines):
#11 217.8     sys.argv ['/tmp/pip-install-b8oectgw/ruamel-yaml-clib_517e9b3f18a94ebea71ec88fbaece43a/setup.py', 'egg_info', '--egg-base', '/tmp/pip-pip-egg-info-n2gr5j35']
#11 217.8     test compiling /tmp/tmp_ruamel_erx3efla/test_ruamel_yaml.c -> test_ruamel_yaml compile error: /tmp/tmp_ruamel_erx3efla/test_ruamel_yaml.c
#11 217.8     Exception: command 'gcc' failed: No such file or directory
#11 217.8     ----------------------------------------
#11 217.8 WARNING: Discarding https://files.pythonhosted.org/packages/8b/25/08e5ad2431a028d0723ca5540b3af6a32f58f25e83c6dda4d0fcef7288a3/ruamel.yaml.clib-0.2.6.tar.gz#sha256=4ff604ce439abb20794f05613c374759ce10e3595d1867764dd1ae675b85acbd (from https://pypi.org/simple/ruamel-yaml-clib/) (requires-python:>=3.5). Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
#11 217.8 ERROR: Could not find a version that satisfies the requirement ruamel.yaml.clib==0.2.6 (from versions: 0.1.0, 0.1.2, 0.2.0, 0.2.2, 0.2.3, 0.2.4, 0.2.6)
#11 217.8 ERROR: No matching distribution found for ruamel.yaml.clib==0.2.6

原有配置

Dockerfile

FROM python:3-alpine

# set work directory
WORKDIR /usr/src/app

# set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

# install dependencies

RUN pip install -U pip setuptools wheel ruamel.yaml ruamel.yaml.clib==0.2.6
COPY ./requirements.txt .
RUN pip install --default-timeout=100 -r requirements.txt

# copy project
COPY . .

docker-compose.yml

version: '3.8'

services: 
  web:
    build: .
    command: python manage.py runserver 0.0.0.0:8000
    volumes:
      - .:/usr/src/app
    ports: 
      - 8000:8000
    env_file: 
      - ./.env.dev

根因说明

报错核心原因是使用的python:3-alpine基础镜像默认未预装C语言编译工具链,ruamel.yaml.clib包包含C扩展模块,安装时需要编译,缺失gcc等工具导致安装失败。

解决方案

将Dockerfile第一行的基础镜像替换为python:3.9-slim-buster即可解决报错。该镜像为基于Debian的精简Python镜像,已预装基础编译依赖,无需额外安装其他组件即可正常安装ruamel.yaml.clib包。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.03 15:27:03