How to properly use relative or absolute imports in Python modules? Stack Overflow

How to properly use relative or absolute imports in Python modules? - Stack Overflow

Ditch relative imports: you should think of your package namespace as a global one, anyway.

The trick to making this palatable is editing sys.path appropriately. Here is some food for thought:

# one directory up
_root_dir = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
sys.path.insert(0, _root_dir)for now
原文地址:https://www.cnblogs.com/lexus/p/2459212.html