Display line numbers in IPython / Jupyter Notebooks

Error reporting from most of the core kernels running in IPython / Jupyter. Laptops indicate the line along which the error occurred; but (at least by default) line numbers are not listed on laptops.

Can I add line numbers in IPython / Jupyter Notebooks?

+103
python ipython jupyter
Jun 11 '12 at 11:59
source share
8 answers

CTRL - M L toggles line numbers in the CodeMirror area. See QuickHelp for other keyboard shortcuts.

In more detail, CTRL - M (or ESC ) will bring you to command mode, then pressing the L keys should switch the visibility of the current cell numbers. In later versions of laptops, Shift-L should switch for all cells.

If you cannot remember the shortcut, pick up the command bar Ctrl-Shift + P ( Cmd + Shift + P on Mac) and find the โ€œline numbersโ€), it should allow you to switch and show you the shortcut.

+125
Jun 11 2018-12-12T00:
source share

In IPython 2.2.0, only input l (lowercase L) works in command mode (activated by pressing Esc). See [Help] - [Keyboard Shortcuts] for other shortcuts.

Alternatively, you can set the default behavior for displaying line numbers by editing custom.js .

+77
Oct 03 '14 at 6:11
source share

Select the Toggle Line Number option in the View menu โ†’ Toggle Line Number.

The menu looks like this

+12
Jan 15 '18 at 6:54
source share

For me, ctrl + m used to save the web page as png, so it does not work properly. But I find a different way.

The toolbar has a bottom called open the palete for commands , you can click it and enter a line, and also see the line number of the switch here.

+5
Apr 08 '16 at 1:31 on
source share

To include default line numbers in all cells at startup, I recommend this link:

https://www.webucator.com/blog/2015/11/show-line-numbers-by-default-in-ipython-notebook/

I quote ...

Change to the jupyter configuration directory, which you can find by typing the following at a command prompt:

jupyter --config-dir

Open or create from there

custom

folder.

In this folder you should find the custom.js file. If it is not there, you can create it. Open it in a text editor and add this code:

define([ 'base/js/namespace', 'base/js/events' ], function(IPython, events) { events.on("app_initialized.NotebookApp", function() { IPython.Cell.options_default.cm_config.lineNumbers = true; } ); } );

+5
Mar 17 '17 at 20:05
source share

Here's how to find the active shortcut (depending on the version of the OS and laptop, it may change)

Help > Keyboard Shortcuts > toggle line numbers

On OSX running ipython3, there was ESC L

+4
Feb 28 '17 at 21:52
source share

You can also find the Toggle Line Numbers View section on the top toolbar of the Jupyter laptop in your browser. This adds / removes line numbers in all cells of the notebook.

For me, Esc + l only added / removed line numbers of the active cell.

+1
Aug 10 '17 at 13:37 on
source share

1. press esc to enter command mode 2.perss l (this is L lowercase) to show the line number

-2
Jan 30 '17 at 4:15
source share



All Articles