I've read about the workarounds (adding to sys.path or more robust solutions), but other libraries don't use such workarounds (for example, this file in tf). I don't expect I really have to either, I want to be able to import on a single line and run - I must be missing something!
To get specific, I have something like the following directory:
project/
foo/
src/
__init__.py
bar.py
foo/
__init__.py
boo.py
I would expect that in bar.py I could simply write something like from foo import boo
, however my IDE, PyCharm, sees this as an error.
So, trusting my IDE, I try from src.foo import boo
but this results in an ImportError, as tested:
Traceback (most recent call last):
File "bar.py", line 1, in <module>
from src.foo import boo
ImportError: No module named 'src'
I verified that the src folder was at sys.path[0]
, however inserting __file__ to it did seem to resolve the issue - I still do not want to use this workaround, but will as a last resort.
I have tried a million other tricks to get this to work without success.
How can I import from a local module without using one of the workarounds?