import os import sys # To import '../../folder_name/foo.py' external_file_path = os.path.abspath(os.path.join('..', '..', 'folder_name')) sys.path.append(external_file_path) from foo import bar