79644654

Date: 2025-05-29 21:34:19
Score: 1.5
Natty:
Report link

To turn line numbers on for a single session in Jupyter Notebook, you can turn them on through View > Show Line Numbers (about halfway down the list, just under Show Log Console). The entry in the view menu will also tell you what the shortcut is, generally Shift+L.

To have the line numbers on by default (I genuinely don't understand why they aren't), you will need to change your settings, and the easiest way for to accomplish that for me was to edit the configuration files directly.

To do this, start by going to the Jupyter config directory.

Navigate to your jupyter config directory, which you can find by typing the following at the command line:

jupyter --config-dir

as per [George Fisher] (https://stackoverflow.com/a/42866228/30672248))

Then, you will need navigate to lab > user-settings > @jupyterlab > notebook-extension. You can do this in your file explorer or by going directly to <config directory>/lab/user-setting/@jupyterlab

There should be a file in there, mine is called tracker.jupyterlab-settings.jupyterlab-settings

Lastly, we need to actually change the configuration. This is based off of MRule's answer (though they seemed to be able to do it from within Jupyter Lab, which I could not get to work).

Open that file with your text editor or code editor of choice, and find "codeCellConfig". Within that entry, you're looking for a line for lineNumbers. If it already exists, make sure it is set to true. If it doesn't, just add it to the bottom of the list! When you're finished, it should look something like this:

{
  ...
  <some other configurations>,
  
  "codeCellConfig": {
    "autoClosingBrackets":true,
    "lineWrap":false,
    "lineNumber":true
  },

  ...
  <some other configurations>
  ...

Be careful to include commas in the correct spaces, each line within "codeCellConfig" is going to need a comma after it, except for the very last one.

If you are changing the configuration file while Jupyter Notebook is running, it probably won't take effect until you restart it again, so consider saving your work and restarting Jupyter Notebook.

Reasons:
  • Blacklisted phrase (1): stackoverflow
  • Long answer (-1):
  • Has code block (-0.5):
  • User mentioned (1): @jupyterlab
  • Low reputation (1):
Posted by: Joshua Meetsma