Jupyter Notebook and nbextensions

Hi
I’m just starting to learn Python and I have a question about setting up Jupyter Notebook.
I really want an extension that formats code when saving a notebook. I managed to find one for Jupyter Lab (jupyterlab_code_formatter), but it doesn’t work in Notebook. I tried to install nbextensions ( jupyter_contrib_nbextensions and jupyter_nbextensions_configurator), but nothing worked and when I try to activate it with the enable command, I get information that the option is deprecated. Is there any way to set up code formatting when saving to notebook?
Jupyter Server 2.16.0; Notebook 7.4.3

Another small question. screen
Can I somehow make the column with the number of steps wider? I tried changing the size of jp-Cell, but it makes it smaller on the right side, and I need to expand it on the left.

As you may have picked up on since you mentioned ‘deprecated’, I think you may be referencing some outdated resources. ’ jupyter_contrib_nbextensions’ is not for anything you have on your machine. There are ways to support it; however, those are being phased out and at this point, since you are just getting started, you are probably better off sticking with the current stuff that is still being developed actively and will continue to be.
These days, for most modern extensions you don’t need to enable/activate as that now gets handled by installing properly. This was not the case with Notebook 6.4 and earlier. However, you are using Notebook 7+, which is based on JupyterLab components. That being the case, I am surprised the extension you reference does not work in Jupyter Notebook 7+. (I do see this issue post that has two people saying that the button isn’t there, but there is no response and no one else has posted there. I tried the mybinder launch button to see if I could see what happened in the Notebook interface but the configuration needs fixing as the session from ‘launch binder’ fails.)

Given those issues, you may want to check this one, jupyter-ruff out that states it works in both interfaces. Read more about it here. I note that the demo seems to launch correctly by clicking the ‘launch binder’ badge (or click here) directly and it has a nice, active in-session guide that steps you through using it and the options.

I don’t know the answer to adjust the properties of the area on the left that you want. I will say though that you don’t really want giant notebooks as they are going to cause you headaches. You probably should be making more smaller notebooks or using Python/IPython directly, or in association with your notebook using %run -i <myscript.py> or <myscript.ipy>, if you are getting that large.

1 Like

At the moment this is true. Automatic code formatting from jupyterlab_code_formatter does not work in Notebook, I do not even see a round icon to the right of the mode, but it works fine in Lab. image.png

I tried to look for alternatives, but all of them are in nbextensions, which I was unable to install.

I directed you to an alternative that isn’t old: jupyter-ruff.