With a project structure like the following:
myproject/
|--- __init__.py
|--- application.py
|--- modules/
|--- __init__.py
|--- parser.py
|--- utils/
|-- __init__.py
|-- helpers.py
In utils/helpers.py
:
def find_stuff():
return stuff
def help_me():
return some_help
In modules/parser.py
, I want to import find_stuff
(and only that).
I've tried the following:
from ..utils.helpers import find_stuff
But...
ImportError: cannot import name 'find_stuff' from 'myproject.utils.helpers' (/Users/myself/myproject/utils/helpers.py)
What should be done here?
Notes:
- everything was working fine with the whole project's policy of absolute import, until I started using Pytest, and then all hell broke loose
- no, I don't want to
from ..utils import helpers
and then usehelpers.find_stuff
inparser.py
— I assume that Python's import system is well-thought enough so that we can precisely avoid that - in the error message, we can see that Python manages to find the correct file, however for some reason it just won't import the function/class/object name, despite it being present in the file