ModuleNotFoundError: No module named 'financials_api_get' when trying to run folder location

53 Views Asked by At

I have a folder directory that looks as such:

-- show_case
  --airflow
    --dags
      fundamental_data_pipeline.py
  __init__.py
  financials_api_get.py

I am trying to run a function get_fundemental_data from financial_api_get.py within fundamental_data_pipeline.py but I get an import error.

My file fundamental_data_pipeline.py looks like this:

sys.path.insert(1, Path(__file__).resolve().parent.parent.parent)
print(Path(__file__).resolve().parent.parent.parent)
from financials_api_get import get_fundemental_data

A print of the path prints show_case but I still get

ModuleNotFoundError: No module named 'financials_api_get'

Why doesn't this work?

EDIT I have an __init__.py file that looks as such:

from financials_api_get import get_fundemental_data
1

There are 1 best solutions below

0
On BEST ANSWER

Problem is Path because sys.path expects only strings.

If you run print(sys.path) then you should see [Path(...), ...]

So you may need str()

p = Path(__file__).resolve().parent.parent.parent

sys.path.insert(0, str(p) )

or .as_posix()

p = Path(__file__).resolve().parent.parent.parent

sys.path.insert(0, p.as_posix() )