I am new to apache airflow and I am following the example code at: https://github.com/apache/airflow/blob/master/airflow/example_dags/tutorial.py
I copied and pasted the code found in the link above in an example.py
inside a folder on my desktop.
The initial code is:
from airflow import DAG
from airflow.operators.bash_operator import BashOperator
If I run python example.py
, I get the error:
from airflow import DAG
ModuleNotFoundError: No module named 'airflow'
Even if I installed airflow as follows:
pip install apache-airflow
What can be a possible solution?
add your modules to one of the folders that Airflow automatically adds to PYTHONPATH package your code into a Python package and install it together with Airflow. The next chapter has a general description of how Python loads packages and modules, and dives deeper into the specifics of each of the three possibilities above.
For example if you create airflow/operators subfolder it will not be accessible because Airflow already has a package named airflow.operators and it will look there when importing from airflow.operators. Never use relative imports (starting with .) that were added in Python 3.
# Default: apache/airflow:master-python3.8 # AIRFLOW_UID - User ID in Airflow containers # Default: 50000 # AIRFLOW_GID - Group ID in Airflow containers # Default: 50000 # _AIRFLOW_WWW_USER_USERNAME - Username for the administrator account. # Default: airflow # _AIRFLOW_WWW_USER_PASSWORD - Password for the administrator account.
The plugins Folder: It is configured with option plugins_folder in section [core]. The DAGS folder in Airflow 2 should not be shared with the webserver. While you can do it, unlike in Airflow 1.10, Airflow has no expectations that the DAGS folder is present in the webserver.
Running:
pip install \
apache-airflow==1.10.10 \
--constraint \
https://raw.githubusercontent.com/apache/airflow/1.10.10/requirements/requirements-python3.7.txt
Worked for me. Check here: https://airflow.apache.org/docs/stable/installation.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With