I am new to airflow and would appreciate your help: My project looks like this:
--AIRFLOWHOME
----dags
------my_dag.py
------labs
--------_ init _.py
--------db_connections.py
In the file my_dag.py I'm trying import my module like this:
from labs import db_connection
It looks fine but when I try to run the following command airflow dags list-import-errors
I get an error: ImportError: cannot import name 'db_connection' from 'labs'
my airflow is not installed on Docker
what is my worng?
I tried to do this, sys.path.append('C:\Users\xxxx\AIRFLOWHOME\dags\labs') but it didn't help
Thank You!
Airflow allows you to use your own Python modules in the DAG and in the Airflow configuration. The following article will describe how you can create your own module so that Airflow can load it correctly, as well as diagnose problems when modules are not loaded properly.
Often you want to use your own python code in your Airflow deployment, for example common code, libraries, you might want to generate DAGs using shared python code and have several DAG python files.
You can do it in one of those ways:
add your modules to one of the folders that Airflow automatically adds to PYTHONPATH
add extra folders where you keep your code to PYTHONPATH
package your code into a Python package and install it together with Airflow.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.