"Javascript Error: IPython is not defined" error when trying to run an interract command in jupyter notebook

41 Views Asked by At

Right so I am trying to use a software called PyWake.

With the following code blocks I am getting the above error:

# prepare for the model combination tool
from py_wake.utils.model_utils import get_models, get_signature
from ipywidgets import interact
from IPython.display import HTML, display, Javascript

# Fix ipywidget label width
display(HTML('''<style>.widget-label { min-width: 20ex !important; }</style>'''))

def print_signature(windFarmModel, **kwargs):
    s = """# insert windFarmModel code below
wfm = %s

validation.add_windFarmModel('MyModelName', wfm)"""% get_signature(windFarmModel, kwargs, 1)

    # Write windFarmModel code to cell starting "# insert windFarmModel code below"
    display(Javascript("""
for (var cell of IPython.notebook.get_cells()) {
    if (cell.get_text().startsWith("# insert windFarmModel code below")){
        cell.set_text(`%s`)
    }
}"""%s))

# setup list of models
models = {n:[(getattr(m,'__name__',m), m) for m in get_models(cls)]
          for n,cls in [('windFarmModel', WindFarmModel),
                        ('wake_deficitModel', WakeDeficitModel),
                        ('rotorAvgModel', RotorAvgModel),
                        ('superpositionModel', SuperpositionModel),
                        ('blockage_deficitModel', BlockageDeficitModel),
                        ('deflectionModel',DeflectionModel),
                        ('turbulenceModel', TurbulenceModel),
                        ('groundModel', GroundModel)
                        ]}
_ = interact(print_signature, **models)

When the interact runs, the drop down boxes appear, but nothing runs. Changing the interact to manual narrows down the error to when the interact is running.

I do have previous code importing the relevant PyWake libraries, and another cell with the " # insert windFarmModel code below" tag at the ready.

I have tried using magic commands, %matplotlib inline, %matplotlib widget, %matplotlib ipympl, all directly before the interact command. None seemed to have an effect.

Ive tried reinstalling literally everything related except for my operating system. Reinstalled my ipython kernel, ipywidgets, ipympl, jupyter, node.js etc. Nothing changed. I have used interact commands elsewhere within my usage of pywake and they have worked.

This code should work because it is literally from the PyWake documentation (the code used to run on the website, but jupyter changes have JavaScript disabled on the documentation webpage.)

I am not particularly experienced with programming, but a friend that was trying to help me directed me here.

Any help would be massively appreciated.

0

There are 0 best solutions below