[英]import module in Jupyter notebook
I cloned a git project which has a folder called NOTEBOOKS and another folder called LOADER.我克隆了一个 git 项目,它有一个名为 NOTEBOOKS 的文件夹和另一个名为 LOADER 的文件夹。 In the LOADER folder, there is a data_loading.py.
在LOADER文件夹下,有一个data_loading.py。 In the NOTEBOOKS folder there is a 01_analysis.ipynb, when I open this notebook using jupyter notebook and I want to run first cell:
在 NOTEBOOKS 文件夹中有一个 01_analysis.ipynb,当我使用 jupyter 笔记本打开这个笔记本并且我想运行第一个单元格时:
from LOADER import data_loading
I get this error:我收到此错误:
ModuleNotFoundError: No module named 'LOADER'
I am sure the code is correct but I need to tell Jupyter where the LOADER is.我确信代码是正确的,但我需要告诉 Jupyter LOADER 在哪里。 Is there anything which I need to add to the Jupyter to know where to fidn LOADER?
有什么我需要添加到 Jupyter 才能知道在哪里找到 LOADER 吗?
This is not related to jupyter notebook but python itself.这与 jupyter notebook 无关,而是 python 本身。 A solution is to create a new module for
data_loading.py
and then install it globally thus allowing you to import it.一种解决方案是为
data_loading.py
创建一个新模块,然后全局安装它,从而允许您导入它。 An alternative will be to add LOADER
to your path using另一种方法是将
LOADER
添加到您的路径中
import sys
sys.path.insert(0, 'path to LOADER')
and then import data_loading
.然后导入
data_loading
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.