Reputation: 23038
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:
from ..utils import helpers
and then use helpers.find_stuff
in parser.py
— I assume that Python's import system is well-thought enough so that we can precisely avoid thatUpvotes: 0
Views: 158
Reputation: 424
Did you read this issue already? It depends on what you want to do. If you're writing something that is purely a module
from myproject.utils.helpers import find_stuff
should work.
Upvotes: 2
Reputation: 2298
Under utils
you do not have an __init__.py
file. I think you will need one and even an empty one will do the trick.
Upvotes: 3