This is the folder structure:


i need to import from and

I also need to import from

I think it would be

import os
import somescript
import someotherscript

You need that root and root/module2 be in sys.path which can be done like this in somescript :

import os
import sys
rootpath = os.path.dirname(os.path.abspath(os.curdir))
mod2path = os.path.join(rootpath,'module2')
import common
import someotherscript

Of course you also need to be sure that all these things exist; it would be nice not to double add them (doesn't actually hurt) to sys.path; and other niceties. You may want to create an empty file named in the various directories. See

Try relative imports.

Seem like just the thing. I've used them. They permit you to import modules from a relative parent package.

They're hard to figure out though. The documentation is somewhat lacking so you might have to tinker until you get it right.

I'm not a fan of, for example from canvas import point because I've spent far too much of my time dealing with subtle bugs introduced by, for example, from coastline import point in the same chunk of code. (Mostly, I admit, not in Python). I just like the self documentation and safety of seeing for example

import canvas
import coastline
myCorner = canvas.point(200,400)
myPromontory = coastline.point(43.32576, -124.38773)

Thus, I'm also not very fond of relative imports. Not saying "bad", but just "I dunno, maybe not usually for me."

I'm talking about dotted relative imports.