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

Airflow启动失败及Pendulum降级构建Wheel报错求助

解决Airflow 2.7.2启动报错及Pendulum降级编译失败问题

问题背景

Airflow 2.7.2启动时触发如下错误:

TIMEZONE = pendulum.tz.timezone(tz)
 ^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: 'module' object is not callable

原因是Pendulum 3.0.0重构了时区模块的调用逻辑,与Airflow 2.7.2不兼容。尝试降级到Pendulum 2.1.2时,又出现编译wheel失败的错误:

Building wheel for pendulum (pyproject.toml) did not run successfully.
│ exit code: 1
╰─> [27 lines of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
ERROR: Failed building wheel for pendulum
Failed to build pendulum
ERROR: Could not build wheels for pendulum, which is required to install pyproject.toml-based projects

解决方案

1. 安装编译依赖(macOS环境)

Pendulum 2.x的C扩展编译需要依赖系统级开发库,先执行以下步骤:

  • 安装Xcode命令行工具:
    xcode-select --install
    
  • 通过Homebrew安装libffi和openssl(未安装Homebrew需先安装):
    brew install libffi openssl
    

2. 配置编译环境变量

设置环境变量让pip找到上述依赖库:

export LDFLAGS="-L$(brew --prefix libffi)/lib -L$(brew --prefix openssl)/lib"
export CPPFLAGS="-I$(brew --prefix libffi)/include -I$(brew --prefix openssl)/include"
export PKG_CONFIG_PATH="$(brew --prefix libffi)/lib/pkgconfig:$(brew --prefix openssl)/lib/pkgconfig"

3. 强制降级Pendulum到兼容版本

执行命令强制安装Pendulum 2.1.2:

pip install pendulum==2.1.2 --force-reinstall --no-cache-dir

4. 验证修复效果

运行以下代码验证Pendulum是否正常工作:

import pendulum
tz = pendulum.tz.timezone('UTC')
print(tz)

无报错则说明安装成功,此时重新启动Airflow即可正常运行。

备选方案:使用Airflow约束文件避免版本冲突

如果希望一次性对齐所有Airflow依赖版本,可使用官方约束文件调整:

pip install --constraint "https://raw.githubusercontent.com/apache/airflow/constraints-2.7.2/constraints-3.12.txt" pendulum

问题原因说明

  • Pendulum 3.0.0对pendulum.tz模块做了破坏性变更,移除了可调用的timezone方法,导致Airflow 2.7.2的时区初始化逻辑失效。
  • Python 3.12与Pendulum 2.x的C扩展编译存在依赖缺失,macOS默认未预装libffi和openssl的开发头文件,导致wheel编译失败。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.26 22:08:16