WSL2 Ubuntu运行Airflow报错ValueError: Unable to configure handler 'processor'
问题:WSL2 Ubuntu中运行Airflow报错(ImportError: cannot import name 'soft_unicode' from 'markupsafe')
环境信息
- 系统:Windows 11 + WSL2 Ubuntu
- Python版本:3.8.10
- Pip版本:20.0.2
- Airflow版本:2.4.1
已执行的安装步骤
按教程执行以下命令无异常:
sudo apt-get install software-properties-common sudo apt-add-repository universe sudo apt-get update sudo apt-get install python-pip sudo pip install apache-airflow # 不加sudo会有路径问题
报错信息
执行airflow命令时出现如下错误:
$ airflow Unable to load the config, contains a configuration error. Traceback (most recent call last): File "/usr/lib/python3.8/logging/config.py", line 563, in configure handler = self.configure_handler(handlers[name]) File "/usr/lib/python3.8/logging/config.py", line 744, in configure_handler result = factory(**kwargs) File "/usr/local/lib/python3.8/dist-packages/airflow/utils/log/file_processor_handler.py", line 45, in __init__ self.filename_template, self.filename_jinja_template = parse_template_string(filename_template) File "/usr/local/lib/python3.8/dist-packages/airflow/utils/helpers.py", line 165, in parse_template_string import jinja2 File "/usr/lib/python3/dist-packages/jinja2/__init__.py", line 33, in <module> from jinja2.environment import Environment, Template File "/usr/lib/python3/dist-packages/jinja2/environment.py", line 15, in <module> from jinja2 import nodes File "/usr/lib/python3/dist-packages/jinja2/nodes.py", line 23, in <module> from jinja2.utils import Markup File "/usr/lib/python3/dist-packages/jinja2/utils.py", line 656, in <module> from markupsafe import Markup, escape, soft_unicode ImportError: cannot import name 'soft_unicode' from 'markupsafe' (/usr/local/lib/python3.8/dist-packages/markupsafe/__init__.py) The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/usr/local/bin/airflow", line 5, in <module> from airflow.__main__ import main File "/usr/local/lib/python3.8/dist-packages/airflow/__init__.py", line 46, in <module> settings.initialize() File "/usr/local/lib/python3.8/dist-packages/airflow/settings.py", line 564, in initialize LOGGING_CLASS_PATH = configure_logging() File "/usr/local/lib/python3.8/dist-packages/airflow/logging_config.py", line 74, in configure_logging raise e File "/usr/local/lib/python3.8/dist-packages/airflow/logging_config.py", line 69, in configure_logging dictConfig(logging_config) File "/usr/lib/python3.8/logging/config.py", line 808, in dictConfig dictConfigClass(config).configure() File "/usr/lib/python3.8/logging/config.py", line 570, in configure raise ValueError('Unable to configure handler ' ValueError: Unable to configure handler 'processor'
解决方案
该错误源于markupsafe版本与jinja2不兼容:旧版jinja2依赖soft_unicode方法,但新版markupsafe已移除该方法,执行以下步骤修复:
- 卸载当前markupsafe:
sudo pip uninstall -y markupsafe
- 安装兼容的旧版本(2.0.1版本保留了
soft_unicode):
sudo pip install markupsafe==2.0.1
- 验证修复结果:
airflow version
若仍有异常,可尝试重新安装Airflow并指定兼容依赖版本:
sudo pip install apache-airflow==2.4.1 markupsafe==2.0.1 jinja2==3.0.3
内容的提问来源于stack exchange,提问作者Sam Fishwick
相关产品推荐
相关产品推荐

