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

Django项目执行Docker compose up时uwsgi编译安装失败求助

Docker Compose部署Django生产环境时uWSGI编译失败解决方案

问题场景

通过docker compose up部署Django生产环境时,执行pip install -r requirements.txt出现uWSGI编译失败错误:

41.76   note: This error originates from a subprocess, and is likely not a problem with pip.
41.76   ERROR: Failed building wheel for uwsgi
41.76   Running setup.py clean for uwsgi
42.71 Successfully built psycopg2
42.71 Failed to build uwsgi
42.71 ERROR: Could not build wheels for uwsgi, which is required to install pyproject.toml-based projects
------
failed to solve: process "/bin/sh -c pip install -r requirements.txt" did not complete successfully: exit code: 1

解决步骤

1. 补充容器内的编译依赖

uWSGI是C语言编写的扩展库,编译时需要依赖编译器和Python开发头文件。如果使用Python官方镜像(如python:3.x-slim),在Dockerfile中添加以下安装命令:

RUN apt-get update && apt-get install -y --no-install-recommends \
    build-essential \
    python3-dev \
    && rm -rf /var/lib/apt/lists/*

完成依赖安装后再执行pip install,确保编译环境完整。

2. 指定稳定版uWSGI

部分新版本uWSGI可能与当前Python版本或容器环境存在兼容性问题,在requirements.txt中指定一个经过验证的稳定版本:

uwsgi==2.0.21

3. 检查pip编译限制

确认requirements.txt或pip命令中没有设置--no-binary=uwsgi这类参数,该参数会强制pip从源码编译uWSGI、跳过预编译wheel的使用。如果有相关配置,移除后重新尝试安装。

4. 确认容器基础镜像类型

确保Docker镜像基于Linux环境(如Debian、Ubuntu)——《Django by Example 4》教程中的Windows环境指主机系统,容器内部仍为Linux。若误用Windows基础镜像,切换为Linux镜像即可解决系统信息获取相关问题。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.12 03:51:01