我总是讨厌在本地模块中导入,最终不得不做很多次这样的事情:try: from package.module import thingexcept ModuleNotFoundError: import os import sys here = os.path.realpath(__file__) root = os.path.split(here)[0] # add more splits to dig deeper in your structure sys.path.append(root) from package.module import thing我希望这会有所帮助。几乎可以肯定不是“正确”的方式来做到这一点。