nteract/papermill

ImportError: attempted relative import with no known parent package

Open

#709 创建于 2022年12月27日

在 GitHub 查看
 (1 评论) (0 反应) (0 负责人)Python (402 fork)batch import
bughelp wanted

仓库指标

Star
 (5,381 star)
PR 合并指标
 (30 天内没有已合并 PR)

描述

I'm trying to turn into a pip package a notebook which runs using Papermill. There are python file local to the package that I want to import into the notebook but it's giving me an error:

# SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
# sys.path.append(os.path.dirname(SCRIPT_DIR))
from . import utils, preprocessing as prep
ImportError: attempted relative import with no known parent package

This way of importing gives this error whether I try to run the notebook manually and through Papermill.

I've also tried importing it directly:

import utils, preprocessing as prep
ModuleNotFoundError: No module named 'utils'

The direct import runs fine if I execute the notebook manually, but when I try to run them through Papermill it doesn't work.

In my package parent I have

import os, sys; sys.path.append(os.path.dirname(os.path.realpath(__file__)))

from . import preprocessing
from . import utils

贡献者指南