Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImportError: cannot import name 'ClassVar' after installing airflow

I have followed the steps to install Airflow from below link

Airflow installation and getting this below error

  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'

Can somebody help me here

like image 790
Chethu Avatar asked Jan 09 '20 12:01

Chethu


1 Answers

I encountered the same error as well in my case:

  • Ubuntu 16.04
  • Python 3.5
  • Airflow 1.10.10

After some checking, I found it was a python version issue that the python3.5 doesn't support the module typing.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.

And checked in PEP 526 I found this feature only support from 3.6, oh....

Thus the solution was to upgrade the Python version to 3.6+ to install 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

After all above, the processes executed successfully. As a perfection for the official guide, the environment requirement for installation will be:

  • Ubuntu 16.04
  • Python 3.6+
  • Airflow 1.10.10
like image 123
Freman Zhang Avatar answered Oct 24 '22 03:10

Freman Zhang