7

I created a very simple DAG to execute a Python file using PythonOperator. I'm using docker image to run Airflow but it doesn't recognize a module where I have my .py file

The structure is like this:

main_dag.py
plugins/__init__.py
plugins/njtransit_scrapper.py
plugins/sql_queries.py
plugins/config/config.cfg

cmd to run docker airflow image:

docker run -p 8080:8080 -v /My/Path/To/Dags:/usr/local/airflow/dags  puckel/docker-airflow webserver

I already tried airflow initdb and restarting the web server but it keeps showing the error ModuleNotFoundError: No module named 'plugins'

For the import statement I'm using:

from plugins import njtransit_scrapper

This is my PythonOperator:

tweets_load = PythonOperator(
    task_id='Tweets_load',
    python_callable=njtransit_scrapper.main,
    dag=dag
)

My njtransit_scrapper.py file is just a file that collects all tweets for a tweeter account and saves the result in a Postgres database.

If I remove the PythonOperator code and imports the code works fine. I already test almost everything but I'm not quite sure if this is a bug or something else.

It's possible that when I created a volume for the docker image, it's just importing the main dag and stopping there causing to not import the entire package?

3
  • 1
    You use import plugins.njtransit_scrapper to import a module from a package. Commented Jun 15, 2019 at 21:07
  • Thanks @Goyo I tried both but sadly it's the same result. Commented Jun 15, 2019 at 21:28
  • Then the package is not accessible from the place where you are importing it. Commented Jun 16, 2019 at 15:58

1 Answer 1

4

To help others who might land on this page and get this error because of the same mistake I did, I will record it here.

I had an unnecessary __init__.py file in dags/ folder.
Removing it solved the problem, and allowed all the dags to find their dependency modules.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.