Unable To Import Python Package Universally
Suppose I have the following directory structure: workspace/ __init__.py ys_manage/ __init__.py manage.py ys_utils/ __init__.py project_dicts.py Now, suppose
Solution 1:
Generally, I've found trying to use relative paths for imports dangerous and very error prone. I'd suggest just putting workspace on your PYTHONPATH (or adding it programatically in __init__.py
) and importing everything relative to that static location. It will make your code more easily readable too, as you'll be able to track down where imports are coming from much more quickly and clearly.
Solution 2:
Try this instead of sys.path.append('..')
:
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
(you'll need to import both sys and os).
Post a Comment for "Unable To Import Python Package Universally"