How to display line numbers in IPython Notebook code cell by default

ipython, jupyter-notebook, python

Solution

In your `custom.js` file (location depends on your OS) put

`IPython.Cell.options_default.cm_config.lineNumbers = true;`

If you can't find custom.js, you can just search for it, but generally it will be in your profile_default folder. If it doesn't exist, create the file at `$(ipython locate profile)/static/custom/custom.js`

If for whatever reason that doesn't work, you can always edit the `custom.js` file in the `site-packages/IPython/html/static/custom/` in the same way.

Problem

I would like my default display for IPython notebook code cells to include line numbers. I learned from Showing line numbers in IPython/Jupyter Notebooks that I can toggle this with ctrl-M L, which is great, but manual. In order to include line numbers by default, I would need to add something to my ipython_notebook_config.py file. Unless I've missed something, there is not an explanation of how to do this in the documentation.

Original source

Related problems