找不到模块 Faker,db_connect 导致 DAG 在 apache 气流中中断

问题描述 投票:0回答:1
Broken DAG: [/opt/airflow/dags/etl_pipeline_dag.py] Traceback (most recent call last):
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/opt/airflow/dags/etl_pipeline_dag.py", line 4, in <module>
    from db_connect import PG
ModuleNotFoundError: No module named 'db_connect'

here db_connect.py is my script which is located in the same directory as dag folder
and etl_pipeline_dag has dag operations where i have imported Faker(python package) to generate fake data. getting the same error even after installing using pip in the same environment where i installed airflow using pip too

我使用 Docker 来运行气流容器,并将官方文档站点中的 Docker Compose 文件保留为默认值。

我尝试制作 Dockerfile 并为其构建镜像,但它也不起作用。

有人可以帮我吗?

python docker-compose airflow directed-acyclic-graphs faker
1个回答
0
投票

我找到了解决方案,它在于使用以下命令创建 Dockerfile:

FROM apache/airflow:2.7.1
RUN pip install faker
COPY db_connect.py /opt/airflow/
COPY config.py /opt/airflow/

保存它并前往终端输入:

docker build . --tag {name_of_your_image}
按 Enter 键运行它,然后转到 docker-compose.yaml 文件并更改:
image: ${AIRFLOW_IMAGE_NAME:-{name_of_your_image}}

运行

docker-compose up -d
,你就不会再遇到这个问题了

注意:您可以向 Dockerfile 添加更多 python 库和自定义模块,但请务必运行命令:

build . --tag {name_of_your_image}
docker compose up -d

© www.soinside.com 2019 - 2024. All rights reserved.