from .widgets import *

# Register a comm target for Javascript initialized widgets..
from IPython import get_ipython
ip = get_ipython()
if ip is not None:
    ip.kernel.comm_manager.register_target('ipython.widget', Widget.handle_comm_opened)

from .widgets import *

# Register a comm target for Javascript initialized widgets..
from IPython import get_ipython
ip = get_ipython()
if ip is not None and hasattr(ip, 'kernel') and hasattr(ip.kernel, 'comm_manager'):
    ip.kernel.comm_manager.register_target('ipython.widget', Widget.handle_comm_opened)

Make it possible to import ipython_widgets without having a kernel or comm manager
Make it possible to import ipython_widgets without having a kernel or comm manager

  from .widgets import *
  
  # Register a comm target for Javascript initialized widgets..
  from IPython import get_ipython
  ip = get_ipython()
- if ip is not None:
+ if ip is not None and hasattr(ip, 'kernel') and hasattr(ip.kernel, 'comm_manager'):
      ip.kernel.comm_manager.register_target('ipython.widget', Widget.handle_comm_opened)
  
Make it possible to import ipython_widgets without having a kernel or comm manager
## Code Before:
from .widgets import *

# Register a comm target for Javascript initialized widgets..
from IPython import get_ipython
ip = get_ipython()
if ip is not None:
    ip.kernel.comm_manager.register_target('ipython.widget', Widget.handle_comm_opened)

## Instruction:
Make it possible to import ipython_widgets without having a kernel or comm manager
## Code After:
from .widgets import *

# Register a comm target for Javascript initialized widgets..
from IPython import get_ipython
ip = get_ipython()
if ip is not None and hasattr(ip, 'kernel') and hasattr(ip.kernel, 'comm_manager'):
    ip.kernel.comm_manager.register_target('ipython.widget', Widget.handle_comm_opened)
