pybel / pybel-jupyter

A PyBEL extension for Jupyter notebooks
MIT License
2 stars 0 forks source link

import pybel_jupyter fails #5

Closed djinnome closed 4 years ago

djinnome commented 4 years ago

Hi folks,

It seems that the latest versions of pybel_jupyter and pybel are out of sync, because pybel.io no longer has the to_jsons function. Which version of pybel should I downgrade to so that this will work?

When I try to run the canonical example,

from pybel.examples import sialic_acid_graph
import pybel_jupyter 

I get the following error:

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-4-1544693f4025> in <module>
      1 from pybel.examples import sialic_acid_graph
----> 2 import pybel_jupyter

~/Projects/Proposals/MARS/Pathogenesis/pybel-jupyter/src/pybel_jupyter/__init__.py in <module>
      3 """A PyBEL extension for Jupyter notebooks."""
      4 
----> 5 from .inline import to_jupyter, to_jupyter_str  # noqa: F401
      6 from .utils import get_version  # noqa: F401
      7 from .visualization import to_html, to_html_file, to_html_path  # noqa: F401

~/Projects/Proposals/MARS/Pathogenesis/pybel-jupyter/src/pybel_jupyter/inline.py in <module>
      9 
     10 from pybel import BELGraph
---> 11 from pybel.io import to_jsons
     12 from .constants import DEFAULT_COLOR_MAP
     13 from .utils import render_template

ImportError: cannot import name 'to_jsons' from 'pybel.io' (/Users/zuck016/Projects/Proposals/MARS/Pathogenesis/pybel/src/pybel/io/__init__.py)
cthoyt commented 4 years ago

Hi @djinnome, you're right, things are a bit out of sync at the moment if you're installing from GitHub. Could you tell me how you've installed everything?

Either way I'll be releasing PyBEL 14 and updating pybel_tools, pybel_jupyter, bel_repository, and bel_commons to reflect that. Each already has a branch where those updates are taking place that you could check out

Also I've renamed all of the to_json() functions to be to_nodelink_json() because there are actually a few different JSON exporters (CX, JGIF, etc.). That's one of the reasons this happened

djinnome commented 4 years ago

Hi @cthoyt

If I install from github, I get this error:

!pip install git+https://github.com/pybel/pybel.git
!pip install git+https://github.com/pybel/pybel-jupyter.git
from pybel.examples import sialic_acid_graph as sag
from pybel_jupyter import to_jupyter
to_jupyter(sag)
Javascript Error: require is not defined

If I install from pip, I get this error

!pip uninstall pybel pybel-jupyter
!pip install pybel
!pip install pybel-jupyter
from pybel.examples import sialic_acid_graph as sag
import pybel_jupyter
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-1-e597df3a85ae> in <module>
      1 from pybel.examples import sialic_acid_graph as sag
----> 2 from pybel_jupyter import to_jupyter
      3 to_jupyter(graph)

~/.pyenv/versions/anaconda3-2019.10/lib/python3.7/site-packages/pybel_jupyter/__init__.py in <module>
      3 """A PyBEL extension for Jupyter notebooks."""
      4 
----> 5 from .inline import to_jupyter, to_jupyter_str  # noqa: F401
      6 from .utils import get_version  # noqa: F401
      7 from .visualization import to_html, to_html_file, to_html_path  # noqa: F401

~/.pyenv/versions/anaconda3-2019.10/lib/python3.7/site-packages/pybel_jupyter/inline.py in <module>
      9 
     10 from pybel import BELGraph
---> 11 from pybel.io import to_jsons
     12 from .constants import DEFAULT_COLOR_MAP
     13 from .utils import render_template

ImportError: cannot import name 'to_jsons' from 'pybel.io' (/Users/zuck016/.pyenv/versions/anaconda3-2019.10/lib/python3.7/site-packages/pybel/io/__init__.py)
cthoyt commented 4 years ago

Hi @djinnome, sorry this fell through the cracks! I just made a fix in pybel/pybel@d6e7e619 and will be releasing a new version of pybel and pybel-jupyter momentarily.

cthoyt commented 4 years ago

The code has been updated in dee415d. Please upgrade both pybel to v0.14.7 and pybel-jupyter to v0.3.0 with

pip install --upgrade pybel
pip install --upgrade pybel-jupyter

and re-open the issue if there are any remaining problems!

djinnome commented 4 years ago

Hi @cthoyt

I upgraded pybel and pybel_jupyter, and I am still getting the javascript error. I am using Jupyter Lab Version 2.1.0.

!pip install --upgrade pybel==0.14.7
!pip install --upgrade pybel_jupyter==0.3.0
from pybel.examples import sialic_acid_graph as sag
import pybel_jupyter
Javascript Error: require is not defined

Interestingly, when I try it in Jupyter notebook, it works fine. I wonder if it is related to the following issue: https://github.com/vega/ipyvega/issues/103 or this: https://github.com/jupyter-widgets/ipywidgets/issues/2379

Anyway, I have a workaround now, so this is less of a priority for me.

Thanks for the superfast response! PyBEL is awesome.

Sincerely

cthoyt commented 4 years ago

@djinnome I've never used Jupyter Lab. Unfortunately, I already feel like this entire Jupyter plugin was hacky at its core, so I'm sure what works is only by accident 😆

I saw what's going on in your other repos at https://github.com/covid-19-causal-reasoning, too. I would love to chat about that once your work starts to mature