ModuleNotFoundError: No module named'xxx' is not in pycharm, so the upper level directory cannot be added to sources root. Method 1: So you can only add the path location in sys before importing
import os import sys
curPath = os.path.abspath(os.path.dirname(__file__)) rootPath = os.path.split(curPath)[0] sys.path.append(os.path.split(rootPath)[0])