使用 Jupyter notebook 在 python 中进行相对导入

文章

我在 python 中导入时遇到了一些麻烦。我不完全明白为什么会出现错误。

我正在使用目录笔记本中的 jupyter notebook。我需要导入prepare_data位于source/prepare_data.py

对于导入,我尝试使用 from ..source.prepare_data import prepare_data

正如这里https://docs.python.org/3/reference/import.html(第 5.7 段)和 python 向我显示一个错误“尝试相对导入超出顶级包”。

包裹

阿尔贝克斯杜夫

您不能从当前工作目录的父目录导入。解决这个问题的简单方法是从根路径开始工作。

这个答案中,您可以找到更多信息。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

使用Jupyter Notebook(Python)导入wordcloud

使用本地ang全局库在python中进行相对导入

使用 jupyter notebook 从“父”文件夹导入 Python

ValueError:尝试在非包中进行相对导入 - 在 python 中进行相对导入

使用Python 3从Jupyter Notebook中相对导入的另一个目录中的模块导入本地函数

无法使用Jupyter Notebook运行python代码

使用Python Jupyter Notebook弹出图

如何在Python中进行相对导入?

使用Jupyter Notebook在Cython中进行unordered_set

将 python 文件导入 Jupyter Notebook

将Python模块导入Jupyter Notebook

使用python对数据进行JSON数据预处理(Jupyter Notebook)

在 Jupyter notebook 中使用 main 方法调用 Python 文件

在 jupyter notebook 中使用 python 循环播放声音

同时使用 Jupyter notebook 和 python 交互显示输出?

使用drawow在python jupyter notebook中动态绘图

使用特定的virtualenv在Jupyter Notebook中执行Python脚本

使用Jupyter Notebook查看从Python运行的MATLAB代码的输出

如何使用 jupyter notebook 修复 python 中的“语法错误”?

在Jupyter Notebook中使用Python虚拟环境

如何使用其他版本的Python运行Jupyter Notebook?

如何使用 Jupyter Notebook 在 Python 中更慢地抓取网站?

在 Python Jupyter Notebook 中使用 Selenium 单击下拉列表

将QVD文件导入Jupyter Notebook-Python2

如何在Jupyter Notebook单元中刷新Python导入?

如何在Jupyter Notebook中导入python .py文件

Jupyter Notebook - Python 3 内核

Jupyter Notebook截断Python输出

被Python 3.5破坏的Jupyter Notebook