5

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
7
  • 3
    looks like helper is not on same level as execute Commented Oct 17, 2013 at 20:27
  • @cox: my bad.. but helper and execute are on same level Commented Oct 17, 2013 at 20:30
  • @cox: but i am executing from a level up.. Commented Oct 17, 2013 at 20:30
  • 1
    If you run python execute.py, do you have the same problem? Commented Oct 17, 2013 at 20:35
  • 1
    Works for me. execute.py and the helper module are really in the same directory? Commented Oct 17, 2013 at 20:35

1 Answer 1

2

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
Sign up to request clarification or add additional context in comments.

1 Comment

The directory structure at the top of the question clearly shows that helper already contains an __init__.py.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.