I am trying to get the hang of modules/packages in Python 2.7. I have a file called tmp.py in /Users/me/dir
import mypackage.datamanagement.lib.models
from mypackage.datamanagement.lib.models import Order
I can run it like this
$pwd #/Users/me/dir
$python tmp.py #runs fine
Everything works fine.
However, if I copy tmp.py to a different location in the package...
$cp tmp.py mypackage/datamanagement/scrips/
And then try to run it with $python mypackage/datamanagement/scripts/tmp.py
from /Users/me/dir I get...
File "mypackage/datamanagement/scrips/tmp.py", line 1, in <module>
import mypackage.datamanagement.lib.models
ImportError: No module named mypackage.datamanagement.lib.models
I have an init.py in all of the relevant directories. I think this has to do with pythonpath. I am osx and if I run
echo $PYTHONPATH
I get a blank line.
Can someone explain what is going on? Is the python working directory set by the location of the python file? And not the location where python is executed?