I am going to feel like a complete idiot when someone answers this question because I know that I have done this before.
Using Python 2.7.5
I have the following file structure:
sandbox/
|-- fun
| |-- __init__.py
| `-- spock.py
|-- __init__.py
`-- something
|-- blah.py
`-- __init__.py
Notice that there is an __init__.py file at each level. Each __init__.py is empty.
spock.py and blah.py are super simple.
spock.py
def helpmespock():
print "help me spock!"
blah.py
import fun.spock
fun.spock.helpmespock()
Executing blah from sandbox and from sandbox/something results in the same error:
[me@computer sandbox]$ python something/blah.py
Traceback (most recent call last):
File "something/blah.py", line 1, in <module>
import fun.spock
ImportError: No module named fun.spock
What am I doing wrong? Why can't I import spock.py from blah.py?
Solved
Thanks to everyone that responded. All of it was helpful.
Everything I did was right except for executing blah.py directly. I added test.py at the top-level which imports blah.py.
test.py:
import something.blah
something.blah.blah()
So now the tree looks like this:
sandbox/
|-- fun
| |-- __init__.py
| `-- spock.py
|-- something
| |-- blah.py
| `-- __init__.py
`-- test.py
Executing the test.py gives me:
[sri@s6000-devel sandbox]$ python test.py
help me spock!