g2nb / igv-jupyter

Extension for Jupyter which integrates igv.js
MIT License
154 stars 13 forks source link

b.show() AttributeError: 'NoneType' object has no attribute 'session' #39

Closed cccnrc closed 4 years ago

cccnrc commented 4 years ago

I followed your installation instruction and everything worked well, but when I try:

>>> import igv
>>> b = igv.Browser({"genome": "hg19"})
>>> b.show()

I get:

Traceback (most recent call last): File "", line 1, in File "/home/enrico/.local/lib/python3.6/site-packages/igv/browser.py", line 89, in show self.comm.send(msg) File "/home/enrico/.local/lib/python3.6/site-packages/igv/browser.py", line 15, in send self.comm.send(message) File "/home/enrico/.local/lib/python3.6/site-packages/ipykernel/comm/comm.py", line 123, in send data=data, metadata=metadata, buffers=buffers, File "/home/enrico/.local/lib/python3.6/site-packages/ipykernel/comm/comm.py", line 66, in _publish_msg self.kernel.session.send(self.kernel.iopub_socket, msg_type, AttributeError: 'NoneType' object has no attribute 'session'

Thank you in advance for any help!

tmtabor commented 4 years ago

The first thing I would do is check what version of ipykernel you have installed. There is a known bug in 4.5.1 where this can happen. If so, you need to upgrade. You can check the version by running:

pip freeze | grep ipykernel

If you're running a more recent version of ipykernel than that, the next thing I would check is to make sur eyou have the igv server extension installed. From the command line, try running: jupyter serverextension list and see if igv appears in the list.

If not, you can install it by running jupyter serverextension enable --py igv. (You may also need to include --sys-prefix, depending on how your environment is set up.)

cccnrc commented 4 years ago

Hi @tmtabor , thank for your rapid answer.

I got both dependencies right:

python3 -m pip freeze | grep ipykernel
ipykernel==5.3.4

jupyter serverextension list
config dir: /home/enrico/.jupyter
    igv  enabled 
    - Validating...
      igv  OK
    jupyter_nbextensions_configurator  enabled 
    - Validating...
      jupyter_nbextensions_configurator 0.4.1 OK

What else can I do?

tmtabor commented 4 years ago

This is a more unusual error then, but we can try to narrow it down. From the notebook where you're experiencing the error, try running:

get_ipython().kernel.comm_manager.comms

This should return a dict object, which is a map of comms (channels of communication between the Jupyter frontend and backend). Ideally there should be one entry in the dict, which is the comm opened by the igv extension when you created the igv.Browser instance.

If you get an error message about get_ipython().kernel being None, then we know this is some deeper configuration issue with Jupyter. On the other hand, if this returns an empty dict (after making sure to run b = igv.Browser({"genome": "hg19"})) then we know it's a problem with the igv extension initializing the comm.

cccnrc commented 4 years ago

I get:

>>> get_ipython().kernel.comm_manager.comms
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'get_ipython' is not defined
tmtabor commented 4 years ago

In Jupyter Notebook, get_ipython() should automatically be in the global context once the IPython kernel has started. If not, something odd is going on. Are you using nteract or a non-default kernel like xeus?

cccnrc commented 4 years ago

I got it now, I was trying this on my local machine and not in Jupyter notebook. So sorry if I wasted your time!