LoginSignup
5
4

More than 3 years have passed since last update.

JupyterNotebookで行番号を常に表示

Last updated at Posted at 2019-02-22

はじめに

JupyterNotebookは、デフォルトで行番号が表示されてません。
行番号が表示されていないと、どの行でエラーが発生したかわかりづらいです。
そこてデフォルトで、行番号を設定する方法をご紹介いたします。
ショートカットキー等で表示させることは可能ですが、後々面倒になってくると思います。

設定方法

①custom.jsの配置箇所
②custom.jsの配置
③JupyteNotebookの起動

①custom.jsの変更に関して
Windowsではデフォルト設定ではC\Users(PCのアカウント名).jupyterが存在します。
その配下にcustomディレクトリがない場合は、新規作成する必要があります。
もしあれば、その中にcustom.jsといったjavascriptファイルを配置する必要があります。
Windows以外でも.jupyterディレクトリは存在しているので、その配下のcustomディレクトリに配置する必要があります。

②custom.jsの配置
custom.jsの中身は以下をコピーしてjsファイルを作成してください。

custom.js
// custom.js
//--------------------------------------------------------------------------------
// Display line numbers in code cell by default
//--------------------------------------------------------------------------------

var cell = Jupyter.notebook.get_selected_cell();
var config = cell.config;
var patch = {
  CodeCell:{
    cm_config:{lineNumbers:true}
  }
}
config.update(patch)

③JupyteNotebookの起動
実際にJupyterNotebookを起動して、行番号が表示されているかご確認ください。
表示されていれば、下図のようになるはずです。
表示されていなければ、JupyterNotebookを再起動してください。
image.png

5
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
4