LoginSignup
44
40

More than 5 years have passed since last update.

Jupyter NotebookをWSLに構築

Last updated at Posted at 2019-02-10

Jupyter経由でPythonが使いたくなり,
自マシンWindows 10のWindows Subsystem for Linuxに構築してみました.

概要

PCスペック

  • Windows 10 Home 1809

導入するもの

  • Windows Subsystem for Linux
  • Ubuntu 18.04 LTS
    • Python3
    • pip3
    • jupyter
    • jupyter-notebook

Windows Subsystem for Linuxを有効に

コントロール パネル\すべてのコントロール パネル項目\プログラムと機能

Windowsの機能の有効化または無効化

Windowsの機能の有効化または無効化

再起動すると有効になります.

Ubuntuの導入

スタートメニュー > Microsoft Store
今回はUbuntu 18.04 をインストールします.

Microsoft Store Ubuntu 18.04

Ubuntuの設定

まず,スタートメニューからUbuntuを起動します.
スタートメニュー > Ubuntu

さらにユーザー名とパスワードを設定します.

パッケージのアップデート

まず,リポジトリを日本のものへ変更します

$ sudo sed -i -e 's%http://.*.ubuntu.com%http://ftp.jaist.ac.jp/pub/Linux%g' /etc/apt/sources.list

つぎに,updateとupgradeを実行します.

$ sudo apt update
$ sudo apt upgrade

pipの導入

pipを導入します.
Python(Python3)は既にインストールされています.

$ sudo apt install python3-pip

さらに,Pythonのパッケージを更新します.

$ sudo -H pip3 install -U pip 

Jupyterの導入

pipを用いてJupyterを導入します.

$ sudo -H pip3 install Jupyter

起動テスト

試しに起動してみます.

$ jupyter notebook

エラー!
起動しません.

Error executing Jupyter command 'notebook': [Errno 2] No such file or directory

jupyter-notebookの導入

Stack overflowの同様の問からいくつか試しました.

  • PATHの追加 => エラー変らず
    • export PATH=$PATH:~/.local/bin/
  • ipythoのインストール => エラー変らず
    • pip3 install "ipython[all]"
  • jupyterの再インストール => エラー変らず
    • pip3 install --upgrade --force-reinstall --no-cache-dir jupyter

結局うまく行ったのは以下でした.

$ sudo -H apt install jupyter-notebook
$ jupyter notebook

ブラウザでもアクセスできました.
http://localhost:8888/

jupyter-notebookの設定

ログイン用にパスワードを設定します.
デフォルトではアクセストークンを発行しますが,コピペするのも面倒なので.

$ jupyter notebook --generate-config
$ jupyter notebook password

jupyter ログイン画面

パスワードは暗号化され~/.jupyter/jupyter_notebook_config.jsonに保存されます.

起動ショートカットの作成

いちいちUbuntuを立ち上げてJupyterを起動するのも面倒なので,
Windows上にショートカットを作成します.

リンク先:C:\Windows\System32\wsl.exe jupyter notebook --no-browser
作業フォルダー:初期ディレクトリ(e.g. %USERPROFILE%\jupyter)

初期ディレクトリはWindows上の表現でOKです.
ショートカットならアイコンをJupyterのものに設定できます.

Jupyterの起動

作成したショートカットを開きます.

jupyter console

ブラウザでhttp://localhost:8888/へアクセスし,ログインします.
jupyter ログイン画面

NotebookをPython 3にて新規作成できます.

jupyter untitled notebook

参考

44
40
3

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
44
40