I want to get the package location before importing it. I basically would like to do
import pkg pkg_path = pkg.__file__
but without import pkg . Now I am doing:
target = "pkg" target_path = None for p in sys.path: search_path = "%s/%s" % (p, target) if os.path.exists(search_path): target_path = search_path
but there are several scenarios in which this will not work ( target does not contain __init__.py , target is inside a compressed EGG file).
Is there a better way to get target_path ?
Thanks,
Yang
Iansr source share