====== 05 上の階層からimport ====== 以下の構成でmain.pyからmod1.pyをimportしたい # tree . ├── conf │   └── mod1.py ├── item │   └── main.py ===== 失敗パターン ===== from ..conf import mod1 if __name__ == '__main__': print(mod1.MOD) エラー # python3.6 item/main.py Traceback (most recent call last): File "item/main.py", line 1, in from ..conf import mod1 ValueError: attempted relative import beyond top-level package ===== 成功パターン ===== Pythonから一つ上の通常では階層はアクセスできないので osでディレクトリを取得 sysでライブラリのインポートパスを追加する currnet_dir = os.path.dirname( os.path.abspath(__file__) ) sys.path.append(currnet_dir + '/../') from conf import mod1 if __name__ == '__main__': print(mod1.MOD) {{tag>Python}}