0

I'm getting module has no attribute import error. I've done a bit of research and followed the answer in this post, but still doing something wrong.

I have the following project structure:

projectFolder
     __init__.py
     main.py
     subfolder
        __init__.py
        api.py
        models.py
        views.py

I would like to run a function contained in subfolder/api.py from main.py.

I've imported the file in subfolder/__init__.py as follows:

import projectFolder.subfolder.api

In main.py I've included this code:

from projectFolder import api

def function():
    get_api_function()
Alan Kavanagh
  • 9,425
  • 7
  • 41
  • 65
Daniela
  • 861
  • 5
  • 11
  • 28

1 Answers1

2

Try this import:

from subfolder.api import get_api_function

If the subfolder is on the python path it should work

Alan Kavanagh
  • 9,425
  • 7
  • 41
  • 65