我在一个名为 engdados 的 Anaconda 环境中安装了气流。当我执行命令气流 initdb 时,我收到以下错误:airflow initdb: cannot import name 'Pendulum' from 'pendulum'
。完整的回溯如下所示:
(engdados) guilherme@Athena-LNX:~$ airflow initdb
Traceback (most recent call last):
File "/home/guilherme/anaconda3/envs/engdados/bin/airflow", line 25, in <module>
from airflow.configuration import conf
File "/home/guilherme/anaconda3/envs/engdados/lib/python3.8/site-packages/airflow/__init__.py", line 47, in <module>
settings.initialize()
File "/home/guilherme/anaconda3/envs/engdados/lib/python3.8/site-packages/airflow/settings.py", line 403, in initialize
configure_adapters()
File "/home/guilherme/anaconda3/envs/engdados/lib/python3.8/site-packages/airflow/settings.py", line 319, in configure_adapters
from pendulum import Pendulum
ImportError: cannot import name 'Pendulum' from 'pendulum' (/home/guilherme/anaconda3/envs/engdados/lib/python3.8/site-packages/pendulum/__init__.py)
(engdados) guilherme@Athena-LNX:~$ service start mysql$
start: unrecognized service
(engdados) guilherme@Athena-LNX:~$ service mysql start$
Usage: /etc/init.d/mysql start|stop|restart|reload|force-reload|status|bootstrap
(engdados) guilherme@Athena-LNX:~$ airflow initdb
Traceback (most recent call last):
File "/home/guilherme/anaconda3/envs/engdados/bin/airflow", line 25, in <module>
from airflow.configuration import conf
File "/home/guilherme/anaconda3/envs/engdados/lib/python3.8/site-packages/airflow/__init__.py", line 47, in <module>
settings.initialize()
File "/home/guilherme/anaconda3/envs/engdados/lib/python3.8/site-packages/airflow/settings.py", line 403, in initialize
configure_adapters()
File "/home/guilherme/anaconda3/envs/engdados/lib/python3.8/site-packages/airflow/settings.py", line 319, in configure_adapters
from pendulum import Pendulum
ImportError: cannot import name 'Pendulum' from 'pendulum' (/home/guilherme/anaconda3/envs/engdados/lib/python3.8/site-packages/pendulum/__init__.py)
问题是:摆锤装好了!当我执行 conda list
命令时,我可以看到如下所示的钟摆:
Name Version Build Channel
pendulum 2.1.2 pypi_0 pypi
我目前检查的内容:
engdados 环境激活了吗?是的
Pendulum 是否安装在 Anaconda 环境中?是的
Anaconda 显示的 Pendulum 版本与 conda list (1.4.4) 中显示的版本不同。为什么?
我不知道发生了什么。提前致谢。
答案 0 :(得分:4)
在钟摆版本 2 中,类 pendulum.Pendulum
被替换为 pendulum.DateTime
。
您的气流版本期望摆锤 1.x,但您的环境有 2.x。
您可以通过创建新环境并安装airflow 2.0(使用pendulum 2.x)来解决此问题。如果您必须使用气流 < 2.0,则需要将摆锤固定到 < 2.0(例如使用 pip 约束)。
答案 1 :(得分:1)
此外,如果您在代码中使用 Pendulum,例如在自定义运算符中,您可以添加
try:
from pendulum import DateTime as Pendulum
except ImportError:
from pendulum import Pendulum