如何在 Jupyter 笔记本中 use/install python code/file

How to use/install python code/file in Juypter notebooks

我从 Git 中心获得了代码文件 data_load_util.py。我正在关注一些使用此导入的教程。使用连接到 SAP Hana 2.0 Express Edition 的 Python 3.xJuypter 笔记本。

文件位置 - https://github.com/SAP-samples/hana-ml-samples/blob/master/Python-API/pal/notebooks/data_load_utils.py

我在教程中使用的命令:

from hana_ml import dataframe 
from data_load_utils import DataSets, Settings

我得到的错误:

ModuleNotFoundError: No module named 'data_load_utils'

自从我发现此实用程序 data_load_util.py 作为代码文件但不确定我如何使用它或将其附加到 python 或 juypter 笔记本以便我可以使用代码和此错误会消失的。

将不胜感激。

Link to error screen shot

您需要通过 sys.path 告诉 Jupyter 在哪里寻找模块。

this 文档中,您可以将模块的子目录添加到 Python 的路径中,如下所示:

import os
import sys
sys.path.insert(0, os.path.abspath('../module-subdirectory'))

然后你可以简单地导入它:

from data_load_utils import DataSets, Settings

注意:这里module-subdirectory是得到data_load_util.py.

的子目录

有关替代方法,请参阅 this 文档。