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 年前99 查看次数
没有答案

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则