jupyter-widgets / pythreejs

A Jupyter - Three.js bridge
https://pythreejs.readthedocs.io
Other
934 stars 185 forks source link

Cannot import in ipython 8.4.0: AttributeError: 'TerminalInteractiveShell' object has no attribute 'kernel' #399

Closed dllu closed 1 year ago

dllu commented 1 year ago

Importing pytheejs in ipython fails.

In [3]: import pythreejs
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Input In [3], in <cell line: 1>()
----> 1 import pythreejs

File /home/dllu/conda-envs/my_conda_env/lib/python3.8/site-packages/pythreejs/__init__.py:6, in <module>
      1 #
      2 # This file automatically generated by
      3 #
      5 from .enums import *
----> 6 from .pythreejs import *
      7 from .traits import *
      8 from ._example_helper import *

File /home/dllu/conda-envs/my_conda_env/lib/python3.8/site-packages/pythreejs/pythreejs.py:12, in <module>
      1 r"""
      2 Python widgets for three.js plotting
      3
   (...)
      9 will use this foundation to build higher-level interfaces to build 3d plots.
     10 """
---> 12 from ipywidgets import Widget, widget_serialization
     13 from traitlets import Unicode, CInt, Instance, List, CFloat, Bool, observe, validate
     14 import numpy as np

File /home/dllu/conda-envs/my_conda_env/lib/python3.8/site-packages/ipywidgets/__init__.py:59, in <module>
     56         return
     57     register_comm_target()
---> 59 _handle_ipython()

File /home/dllu/conda-envs/my_conda_env/lib/python3.8/site-packages/ipywidgets/__init__.py:57, in _handle_ipython()
     55 if ip is None:
     56     return
---> 57 register_comm_target()

File /home/dllu/conda-envs/my_conda_env/lib/python3.8/site-packages/ipywidgets/__init__.py:47, in register_comm_target(kernel)
     45 def register_comm_target(kernel=None):
     46     """Register the jupyter.widget comm target"""
---> 47     comm_manager = get_comm_manager()
     49     comm_manager.register_target('jupyter.widget', Widget.handle_comm_opened)
     50     comm_manager.register_target('jupyter.widget.control', Widget.handle_control_comm_opened)

File /home/dllu/conda-envs/my_conda_env/lib/python3.8/site-packages/ipywidgets/__init__.py:33, in get_comm_manager()
     30 def get_comm_manager():
     31     ip = get_ipython()
---> 33     if ip is not None and ip.kernel is not None:
     34         return get_ipython().kernel.comm_manager

AttributeError: 'TerminalInteractiveShell' object has no attribute 'kernel'
ipython --version
8.4.0
pip show pythreejs
Name: pythreejs
Version: 2.4.2
Summary: Interactive 3D graphics for the Jupyter Notebook and JupyterLab, using Three.js and Jupyter Widgets.
Home-page: https://github.com/jupyter-widgets/pythreejs
Author: PyThreejs Development Team
Author-email: jason@jasongrout.org
License: BSD-3-Clause
Location: /home/dllu/conda-envs/my_conda_env/lib/python3.8/site-packages
Requires: ipydatawidgets, ipywidgets, numpy, traitlets
Required-by:

Please do not ask me to not import pythreejs in ipython. I am not interested in using pythreejs; I just want to do some quick experiments in ipython but it is transitively imported by some code I'm working on.

martinRenou commented 1 year ago

Thanks for reporting, this should be fixed by https://github.com/jupyter-widgets/ipywidgets/pull/3737