EMR Studio - Can you import local code into a notebook?

0

We are trying to use EMR Studio as a development environment for a medium complexity project which has the code split out into multiple files for testing and maintainability. There's simply too much code to have in one long file.

I cannot work out how to import local code into a notebook to run or test it.

Example layout

Here is a simplified example (our project is much larger):

my_notebook.ipynb
my_project/
     __init__.py
     model.py
     report.py

In the notebook we might have a cell like:

from my_project.model import DataModel
from my_project.report import Report

report = Report(DataModel(spark))

report.show()

The current result is:

An error was encountered:
No module named 'my_project'
Traceback (most recent call last):
ModuleNotFoundError: No module named 'my_project'

Is this possible?

Execution environment

It appears that the Python execution environment and the shell environment are completely separate, and the current directory is not available to the Python interpreter:

Execution environmentKeyValue
PythonUserlivy
PythonCurrent working dir/mnt/var/lib/livy
%%shUseremr-notebook
%%shCurrent working dir/home/emr-notebook/e-<HEX_STRING>

The /home/emr-notebook/... dir appears to contain our code, but the livy user which we appear to be running as doesn't permission to look at it. So even if we could guess the CWD and add it to the Python path it appears Python would not have permissions to read the code.

質問済み 2年前101ビュー
回答なし

ログインしていません。 ログイン 回答を投稿する。

優れた回答とは、質問に明確に答え、建設的なフィードバックを提供し、質問者の専門分野におけるスキルの向上を促すものです。

質問に答えるためのガイドライン

関連するコンテンツ