IAMconsortium / pyam

Analysis & visualization of energy & climate scenarios
https://pyam-iamc.readthedocs.io/
Apache License 2.0
226 stars 118 forks source link

Javascript Error: IPython is not defined #591

Closed stefaneidelloth closed 2 years ago

stefaneidelloth commented 2 years ago

If I import pyam in JupyterLab 3.2.3 on Windows I get the warning

Javascript Error: IPython is not defined

image

=> How to avoid that?

danielhuppmann commented 2 years ago

Thanks for reporting this issue! The error is caused by this line

https://github.com/IAMconsortium/pyam/blob/732752c9c1af9ab453b28584a4a4e05cc9930c0a/pyam/__init__.py#L45

which deactivates in-cell scrolling when working in Jupyter notebooks. Jupyterlab-notebooks don't have in-cell scrolling anyway. Not sure why the try-except-block doesn't work here...

A quick-fix would be to remove these 6 lines locally, in your installation.

About a longer-term fix: @gidden introduced this specification for Jupyter-notebooks, so I'd defer to him about whether to simply remove it. Not sure if there is a good way to check whether a user is working Jupyter notebooks or Jupyterlab-notebooks...

stefaneidelloth commented 2 years ago

JupyterLab does not provide the global IPython variable in JavaScript.

Not sure if there is a good way to check whether a user is working Jupyter notebooks or Jupyterlab-notebooks

https://stackoverflow.com/questions/15411967/how-can-i-check-if-code-is-executed-in-the-ipython-notebook/24937408

def in_ipynb():
    try:
        cfg = get_ipython().config 
        if cfg['IPKernelApp']['parent_appname'] == 'ipython-notebook':
            return True
        else:
            return False
    except NameError:
        return False
danielhuppmann commented 2 years ago

Seems that this discussion is outdated.

Just tried this, when I run get_ipython().config['IPKernelApp'], the only attribute in the dictionary is a connection_file, and there seem to be no relevant info in that file for distinguishing between Jupyter and Jupyter-lab...

stefaneidelloth commented 2 years ago

Verified that the check does not work any more. As an alternative to checking JupyterLab vs Notebook, here is a check in Javascript:

shell.run_cell_magic(
    u"javascript",
    u"",
    u"if (typeof IPython !== 'undefined') { IPython.OutputArea.prototype._should_scroll = function(lines) { return false; }}",
)