我是Airflow的新手。我是由pip install apache-airflow
安装的。当我在终端中运行命令airflow initdb
时,我收到以下错误。我在安装过程中哪里出错了,如何解决这个问题?
aamir@aamir-Inspiron-3542:~$ airflow initdb
[2019-03-30 18:32:27,309] {__init__.py:51} INFO - Using executor SequentialExecutor
DB: sqlite:////home/aamir/airflow/airflow.db
[2019-03-30 18:32:31,790] {db.py:338} INFO - Creating tables
INFO [alembic.runtime.migration] Context impl SQLiteImpl.
INFO [alembic.runtime.migration] Will assume non-transactional DDL.
ERROR [airflow.models.DagBag] Failed to import: /home/aamir/anaconda3/lib/python3.7/site-packages/airflow/example_dags/example_http_operator.py
Traceback (most recent call last):
File "/home/aamir/anaconda3/lib/python3.7/site-packages/airflow/models.py", line 374, in process_file
m = imp.load_source(mod_name, filepath)
File "/home/aamir/anaconda3/lib/python3.7/imp.py", line 171, in load_source
module = _load(spec)
File "<frozen importlib._bootstrap>", line 696, in _load
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/home/aamir/anaconda3/lib/python3.7/site-packages/airflow/example_dags/example_http_operator.py", line 27, in <module>
from airflow.operators.http_operator import SimpleHttpOperator
File "/home/aamir/anaconda3/lib/python3.7/site-packages/airflow/operators/http_operator.py", line 21, in <module>
from airflow.hooks.http_hook import HttpHook
File "/home/aamir/anaconda3/lib/python3.7/site-packages/airflow/hooks/http_hook.py", line 23, in <module>
import tenacity
File "/home/aamir/anaconda3/lib/python3.7/site-packages/tenacity/__init__.py", line 352
from tenacity.async import AsyncRetrying
^
SyntaxError: invalid syntax
Done.
在Python 3.7中,async
是一个保留关键字,这意味着它不能在模块和变量名中使用。这在以前的Python版本中是有效的,但从3.7开始,引发了SyntaxError
。
在您的情况下,Airflow预先安装了示例DAG,在运行airflow initdb
时会对其进行解析。其中一些DAG使用SimpleHttpOperator
,这取决于http_hook.py
。该钩子还取决于tenacity
库,它试图导入async
模块作为初始化的一部分:
from tenacity.async import AsyncRetrying
要解决此问题,请等待/安装更新Tenacity的Airflow v1.10.3(请参阅AIRFLOW-2876)。或者,您可以降级Python版本。您可以使用3.7.3看到导入失败:
$ docker run --rm -it python:3.7
Python 3.7.3 (default, Mar 27 2019, 23:40:30)
>>> from tenacity.async import AsyncRetrying
File "<stdin>", line 1
from tenacity.async import AsyncRetrying
^
SyntaxError: invalid syntax
但它在版本3.6.8中工作正常:
$ docker run --rm -it python:3.6
Python 3.6.8 (default, Feb 6 2019, 12:07:20)
>>> from tenacity.async import AsyncRetrying
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'tenacity'