So first... my directory structure..
---script/execute.py
|
L---helper---foo.py
L-----bar.py
L--- __init__.py
Now, execute.py calls both foo and bar .py as
from helper.foo import some_func
I am trying to run this as:
python script/execute.py
But I am getting this import error
from helper.foo import some_func
Import error: No module named helper??
What am I missing (note that there is no init inside script folder??)?
Thanks
asked Oct 17, 2013 at 20:22
frazman
33.5k82 gold badges194 silver badges284 bronze badges
1 Answer 1
You should check out http://docs.python.org/2/tutorial/modules.html#packages
The "too long, didn't read" of it is that you need to have a file called __init__.py in your helper directory, e.g.,
$ touch helper/__init__.py
The file can also contain Python code, but in the simplest form an empty file is ok.
sth
231k56 gold badges288 silver badges370 bronze badges
answered Oct 17, 2013 at 21:05
Daniel Landau
2,3242 gold badges15 silver badges19 bronze badges
Sign up to request clarification or add additional context in comments.
1 Comment
jwodder
The directory structure at the top of the question clearly shows that
helper already contains an __init__.py.lang-py
python execute.py, do you have the same problem?execute.pyand thehelpermodule are really in the same directory?