0

I have a structure as :

- api.py
- reports (folder)
  |_app.py
  |_pages (folder)
    |_page1.py

In reports, app.py calls page1.py. I need to execute app.py from api.py. I am trying to "from reports import app" but I get :

ModuleNotFoundError: No module named 'pages'

Any ideas on how I can do this? I am new to modules in Python, so any help would be highly appreciated.

Vasilis
  • 85
  • 1
  • 9

2 Answers2

0

from reports import app
That would work if reports is a module and app is a function inside it. Since reports is a folder, this approach wouldn't work. An easy solution would be

import sys
sys.path.append('specify path to reports folder')
import app
Abhinav Mathur
  • 7,791
  • 3
  • 10
  • 24
0

You need to add empty __init__.py file to your pages folder. For more details see What is __init__.py for?

n0nvme
  • 1,248
  • 8
  • 18