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.

demandé il y a 2 ans95 vues
Aucune réponse

Vous n'êtes pas connecté. Se connecter pour publier une réponse.

Une bonne réponse répond clairement à la question, contient des commentaires constructifs et encourage le développement professionnel de la personne qui pose la question.

Instructions pour répondre aux questions