1

I have a file survey_monkey.py and a directory surveymonkey in the dag folder. There is a python script named surveys.py in the directory surveymonkey.

from surveys import Surveys

# defining DAG arguments

# You can override them on a per-task basis during operator initialization
default_args = {
    'owner': 'survey_monkey',
    'start_date': days_ago(0),
    'email': ['[email protected]'],
    'email_on_failure': False,
    'email_on_retry': False,
    'retries': 1,
    'retry_delay': timedelta(minutes=5),
}

This givs me an error saying

Broken DAG: [/home/ubuntu/airflow/dags/survey_tools/survey_monkey.py] Traceback (most recent call last):
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/home/ubuntu/airflow/dags/survey_tools/survey_monkey.py", line 11, in <module>
    from surveys import Surveys
ModuleNotFoundError: No module named 'surveys'

How can I fix it?

2 Answers 2

1

The import path should be relative to dags folder. Since surveys stays inside surveymonkey which is in dag folder.

Replace following line:

from surveys import Surveys

with:

from surveymonkey.surveys import Surveys
Sign up to request clarification or add additional context in comments.

Comments

0

You can do one of the following:

  1. add your modules to one of the folders that Airflow automatically adds to PYTHONPATH
  2. add extra folders where you keep your code to PYTHONPATH
  3. package your code into a Python package and install it together with Airflow.

Airflow has Modules Management documentation that explains it thoroughly.

In your case the module you wish to import exist in the DAG folder (Which already exist in PYTHONPATH) so you can simply import it with a path relative to your DAG folder. The following import should work:

from survey_tools.survey_monkey.surveys import Surveys

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.