My folder trees:
./
├── README.MD
├── basic
│ └── thresh.py
├── images
│ └── figure.jpg
└── utils
├── util.py
└── util.pyc
I want to import util.py in thresh.py:
import sys
sys.path.append('../utils')
import util
When I run command $ python thresh.py in the basic folder, it's allright. But run $ python ./basic/thresh.py in the topmost folder, I will get the error:
ImportError: No module named util
So how to make $ python ./basic/thresh.py and $ python thresh.py both work to import file by given the file's relative path to executed file regardless of python command path?