jupyter-incubator / sparkmagic

Jupyter magics and kernels for working with remote Spark clusters
Other
1.33k stars 447 forks source link

[QST] How to automatically load sparkmagic.magics when open a new ipython kernel tab #804

Closed wjxiz1992 closed 1 year ago

wjxiz1992 commented 1 year ago

Is there any way to avod typing %load_ext sparkmagic.magics every time for a new notebook? I tried jupyter serverextension enable --py sparkmagic and i can see the added extension in $USER/.jupyter/jupyter_notebook_config.json. But when I open a new notebook, it still requires the load_ext action. I also tried to add to jupyter_notebok_config.py at field c.NotebookApp.nbserver_extensions = {"sparkmagic.magics": True}, but this results in an error:

W 2023-01-31 18:10:18.354 ServerApp] sparkmagic.magics | extension failed loading with message: 'NoneType' object is not callable
[E 2023-01-31 18:10:18.354 ServerApp] sparkmagic.magics | stack trace
    Traceback (most recent call last):
      File "/home/allxu/miniconda3/lib/python3.8/site-packages/jupyter_server/extension/manager.py", line 362, in load_extension
        extension.load_all_points(self.serverapp)
      File "/home/allxu/miniconda3/lib/python3.8/site-packages/jupyter_server/extension/manager.py", line 234, in load_all_points
        return [self.load_point(point_name, serverapp) for point_name in self.extension_points]
      File "/home/allxu/miniconda3/lib/python3.8/site-packages/jupyter_server/extension/manager.py", line 234, in <listcomp>
        return [self.load_point(point_name, serverapp) for point_name in self.extension_points]
      File "/home/allxu/miniconda3/lib/python3.8/site-packages/jupyter_server/extension/manager.py", line 225, in load_point
        return point.load(serverapp)
      File "/home/allxu/miniconda3/lib/python3.8/site-packages/jupyter_server/extension/manager.py", line 147, in load
        return loader(serverapp)
    TypeError: 'NoneType' object is not callable
jianzhenwu commented 1 year ago

Add ipython_config file(~/.ipython/profile_default/ipython_config.py)with the following content

c.InteractiveShellApp.extensions = [ 'sparkmagic.magics' ]