I am using python 2:
python --version
Python 2.7.13 :: Continuum Analytics, Inc.
I have the following project structure:
.
foo
is the directory which contains everything, including start.py
So when from start.py
you do this
from foo.bar2.mod2 import mod2_f
python looks for a foo
module (foo
is a module because it contains __init__.py
), which too high in your directory structure. I suppose it works from the IDE because IDE adds every module directory to pythonpath. But not from command line it doesn't.
simple fix since bar2
is a directory at the same level as start.py
:
from bar2.mod2 import mod2_f
note that from
works differently in python 3. See ImportError on python 3, worked fine on python 2.7, that's probably why PyCharm complains when fixing the import line. You should configure PyCharm so it uses Python 2 and not Python 3 for it to work, or just drop the from
syntax altogether and do:
import bar2.mod2.mod2_f