我使用以下命令为python3创建了virtualenv:
virtualenv -p $(which python3) ENV
然后激活源
source /Users/myusername/ENV/bin/activate
安装apache-airflow:
pip install apache-airflow
然后which airflow
产生/Users/myusername/ENV/bin/airflow
但是当我尝试使用以下方法初始化数据库时:
airflow initdb
我遇到以下错误:
{db.py:350} INFO - Creating tables
INFO [alembic.runtime.migration] Context impl SQLiteImpl.
INFO [alembic.runtime.migration] Will assume non-transactional DDL.
WARNI [airflow.utils.log.logging_mixin.LoggingMixin] cryptography not found - values will not be stored encrypted.
ERROR [airflow.models.DagBag] Failed to import: /Library/Python/2.7/site-packages/airflow/example_dags/example_http_operator.py
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/airflow/models/__init__.py", line 413, in process_file
m = imp.load_source(mod_name, filepath)
File "/Library/Python/2.7/site-packages/airflow/example_dags/example_http_operator.py", line 27, in <module>
from airflow.operators.http_operator import SimpleHttpOperator
File "/Library/Python/2.7/site-packages/airflow/operators/http_operator.py", line 21, in <module>
from airflow.hooks.http_hook import HttpHook
File "/Library/Python/2.7/site-packages/airflow/hooks/http_hook.py", line 23, in <module>
import tenacity
File "/Library/Python/2.7/site-packages/tenacity/__init__.py", line 375, in <module>
from tenacity.tornadoweb import TornadoRetrying
File "/Library/Python/2.7/site-packages/tenacity/tornadoweb.py", line 24, in <module>
from tornado import gen
File "/Library/Python/2.7/site-packages/tornado-6.0.3-py2.7-macosx-10.14-intel.egg/tornado/gen.py", line 126
def _value_from_stopiteration(e: Union[StopIteration, "Return"]) -> Any:
^
SyntaxError: invalid syntax
Done.
(ENV) ---------------------------------------------------------
似乎示例脚本使用python 2.7,但无法识别函数定义语法。 apache-airflow软件包是否需要在下一个版本中修复,或者我可以采取一些措施来解决? 我尝试解决此问题: 使用python2.7代替python3 然后在Mac上启用的默认python 2.7上安装airflow,但这会引发其他错误,例如软件包“ six”不兼容。
答案 0 :(得分:0)
您需要关闭要在配置文件中加载的示例DAG,才能解决此问题。
无论如何,当您告诉气流安装到Python 3虚拟环境中时,它使用2.7 Python似乎很奇怪。