gpt4 book ai didi

python - 导入错误 : cannot import name 'ClassVar' after installing airflow

转载 作者:行者123 更新时间:2023-12-03 14:15:58 25 4
gpt4 key购买 nike

我已按照以下链接安装 Airflow 的步骤

Airflow installation并得到以下错误

  Traceback (most recent call last):
File "/usr/local/bin/airflow", line 25, in <module>
from airflow.configuration import conf
File "/usr/local/lib/python3.5/dist-packages/airflow/__init__.py", line 42, in <module>
from airflow.models import DAG
File "/usr/local/lib/python3.5/dist-packages/airflow/models/__init__.py", line 21, in
<module>
from airflow.models.baseoperator import BaseOperator, BaseOperatorLink # noqa: F401
File "/usr/local/lib/python3.5/dist-packages/airflow/models/baseoperator.py", line 30, in
<module>
from typing import Any, Callable, ClassVar, Dict, FrozenSet, Iterable, List, Optional,
Set, Type, Union
ImportError: cannot import name 'ClassVar'

有人可以在这里帮助我吗

最佳答案

在我的情况下,我也遇到了同样的错误:

  • Ubuntu 16.04
  • Python 3.5
  • Airflow 1.10.10

  • 经过一番检查,我发现是python3.5不支持模块类型的python版本问题。ClassVar: https://docs.python.org/3.5/library/typing.html
    As introduced in PEP 526, a variable annotation wrapped in ClassVar indicates that a given attribute is intended to be used as a class variable and should not be set on instances of that class.

    并 checkin PEP 526我发现这个功能只支持3.6,哦....

    因此解决方案是将 Python 版本升级到 3.6+ 以安装 Airflow 1.10。
    sudo add-apt-repository ppa:deadsnakes/ppa
    sudo apt-get update
    sudo apt-get install python3.7
    sudo apt install build-essential libssl-dev libffi-dev python3.7-dev
    sudo apt-get install python3.7-venv

    综上所述,进程成功执行。
    作为官方指南的完善,安装环境要求为:
  • Ubuntu 16.04
  • Python 3.6+
  • Airflow 1.10.10
  • 关于python - 导入错误 : cannot import name 'ClassVar' after installing airflow,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59664445/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com