I have the following project structure:
airflow_ci
plugins
sql_operator.py
utilities
__init__.py
db.py
From sql_operator.py, I want to import the function get_primary_keys that is in db.py. For that, I have coded:
from utilities.db import get_primary_keys
Also, I have added the path to PYTHONENV with:
export PYTHONENV=/home/ubuntu/airflow_ci/utilities
If I do printenv PYTHONENV I get the following:
/home/ubuntu/airflow_ci/utilities
Entering in python and printing sys.path, gives me the following:
['', '/home/ubuntu/airflow_ci/utilities', '/usr/lib/python36.zip', '/usr/lib/python3.6', '/usr/lib/python3.6/lib-dynload', '/home/ubuntu/.local/lib/python3.6/site-packages', '/usr/local/lib/python3.6/dist-packages', '/usr/lib/python3/dist-packages']
Still, I get the error:
Traceback (most recent call last):
File "/home/ubuntu/.local/lib/python3.6/site-packages/airflow/plugins_manager.py", line 182, in <module>
m = imp.load_source(namespace, filepath)
File "/usr/lib/python3.6/imp.py", line 172, in load_source
module = _load(spec)
File "<frozen importlib._bootstrap>", line 684, in _load
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/home/ubuntu/airflow_ci/plugins/sql_operator.py", line 2, in <module>
from utilities.db import get_primary_keys_query
ModuleNotFoundError: No module named 'utilities'
I have tried with more export statements, like:
export PYTHONPATH=$PYTHONPATH:/home/ubuntu/airflow_ci
export PYTHONPATH=$PYTHONPATH:/home/ubuntu/airflow_ci/utilities
export PYTHONPATH=/home/ubuntu/airflow_ci/utilities/
export PYTHONPATH=home/ubuntu/airflow_ci/utilities
Is it possible to solve this without adding a sys.append line of code in sql_operator.py?