EDIT Nov 2014 (3 years later):
Python 2.6 and 3.x support proper relative imports, where you can avoid hacking. With this method, you know that you are getting relative imports, not absolute imports. ".." means go to the directory above me:
from ..Common import Common
As a caution, this will only work if you run your python as a module, outside of it. For example:
python -m Proj
The original hacker way
This method is still often used in some situations where you never actually install your package. For example, it is popular among Django users.
You can add Common / to your sys.path (a list of paths to which python is trying to import things):
import sys, os sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'Common')) import Common
os.path.dirname(__file__) just gives you the directory where your current python file is located, and then we go to the "Common /" directory and import the "Common" module.
Dave Sep 21 '11 at 20:13 2011-09-21 20:13
source share