3

I installed airflow within one of my Anaconda envs named engdados. When I execute the command airflow initdb I'm getting the following error: airflow initdb: cannot import name 'Pendulum' from 'pendulum'. The full trace back is shown below:

(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)

The problem is: the pendulum is installed! When I execute the conda list command I can see the Pendulum there as follows:

 Name                    Version                   Build  Channel

pendulum                  2.1.2                    pypi_0    pypi

What I've checked so far:

Is the engdados environment activated? Yes

Is the Pendulum installed on Anaconda environment? Yes

The version of Pendulum the Anaconda shows is different of the one showed in conda list (1.4.4). Why?

I have no idea what is going on. Thanks in advance.

4

2 回答 2

4

在 pendulum 版本 2 中,类pendulum.Pendulum被替换为pendulum.DateTime.

您的气流版本需要摆 1.x,但您的环境有 2.x。

您可以通过创建新环境并安装气流 2.0(使用 pendulum 2.x)来解决此问题。如果您必须使用气流 < 2.0,则需要将摆固定到 < 2.0(例如使用 pip 约束)。

于 2020-12-20T07:26:15.920 回答
1

此外,如果您在代码中使用 Pendulum,例如在自定义运算符中,您可以添加

try:
    from pendulum import DateTime as Pendulum
except ImportError:
    from pendulum import Pendulum
于 2021-06-01T15:38:23.357 回答