[英]Why docker-compose python no module found for airflow operator
I am working on tests for docker-airflow postgres etl.我正在对 docker-airflow postgres etl 进行测试。 My project structure currently looks like this:
我的项目结构目前如下所示:
docker-airflow
|
├── Dockerfile
├── __init__.py
├── dags
│ ├── __init__.py
│ ├── pandas_etl.py
│ └── tuto.py
├── docker-compose.yml
├── operators
├── __init__.py
└── pandas_etl_over_postgres_operator.py
When importing my pandas_etl_over_postgres_operator.py
into the pandas_etl.py
dag, I am getting an error that the module is not found.将我的
pandas_etl_over_postgres_operator.py
导入到pandas_etl.py
dag 时,我收到一个错误,提示未找到该模块。
The pandas_etl.py import code is: pandas_etl.py 导入代码是:
from operators.pandas_etl_over_postgres_operator import PandasETLOverPostgresOperator
I have tried the following two alternatives, they also give the same error.我尝试了以下两种替代方法,它们也给出了相同的错误。
from .operators.pandas_etl_over_postgres_operator import PandasETLOverPostgresOperator
and和
from ..operators.pandas_etl_over_postgres_operator import PandasETLOverPostgresOperator
The import works fine locally but fails when I build and run using docker-compose.导入在本地工作正常,但在我使用 docker-compose 构建和运行时失败。
Please note that for airflow, by default, the [core]
> dags_folder
will have a value of /usr/local/airflow/dags
meaning that airflow will look for dags at path /usr/local/airflow/dags
.请注意,对于气流,默认情况下,
[core]
> dags_folder
的值为/usr/local/airflow/dags
dags_folder
/usr/local/airflow/dags
dags_folder
意味着气流将在路径/usr/local/airflow/dags
dags_folder
/usr/local/airflow/dags
dags_folder
。
As a result, all your dags code should be inside that folder and hence, here are a few things that you need to change for your code to work:因此,您所有的 dags 代码都应该在该文件夹中,因此,您需要更改以下几项内容才能使代码正常工作:
docker-compose.yml
file:docker-compose.yml
文件中:- ./dags:/usr/local/airflow/dags/dags
- ./logs:/usr/local/airflow/dags/logs
- ./operators:/usr/local/airflow/dags/operators
pandas_etl.py
file:pandas_etl.py
文件中:from operators.pandas_etl_over_postgres_operator import PandasETLOverPostgresOperator
Hope it helps!希望能帮助到你!
I think it is because you need to put your operator inside a plugins directory and mount that into a container.我认为这是因为您需要将操作员放在插件目录中并将其安装到容器中。 Have a look at the Puckle documentation regarding plugins here .
在此处查看有关插件的 Puckle 文档。 You can also see and change where your particular airflow instance looks for plugins by checking your configuration file here
您还可以通过在此处检查配置文件来查看和更改特定气流实例查找插件的位置
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.