Python paths/import in standalone programs -
i'm writing package small application. distributed portable python, code has no access windows settings.
the program has structure:
mypr __init__.py gui __init.__.py prlib __init__.py
i trying from mypr.gui import gui
in prlib
but, of course, mypr
not defined. add win path, edit pth file or append sys.path
current directory, but: portable application , directory change.
so, how can sure python have mypr
in path, both during development , deployment? without changing *.pth or editing windows path
. there reasonable hack during runtime link mypr
?
or, possible import package "relatively"? tried from .gui import gui
, no luck.
if want able access 'gui' module in directory above 'prlib' can achieve by:
import os import sys sys.path.append(os.path.join(os.dirname(__file__), '../'))
then should able import 'gui' via:
from gui import gui
Comments
Post a Comment