14
17

More than 3 years have passed since last update.

python仮想環境(venv)にインストールしたjupyter-labを使う

Last updated at Posted at 2019-11-23

すでにQiitaにも投稿がありましたが、情報が点在していたので整理しました。

ポイントは2つです。
* 仮想環境にインストールしたカーネルを使う
* 実行環境(python)のパスに仮想環境を追加する

わかってしまうと当たり前なんですが、調べずに元の環境にインストールしてしまうことが多いです。

環境

  • MacOS 10.15.1
  • python 3.7.4 (pyenv/anyenv)

仮想環境作成

仮想環境を作成するモジュールはインストール済みとします。

$ virtualenv test
$ source test/bin/activate
$ pip install keras
$ pip install jupyterlab

仮想環境にカーネルをインストール

$ pip install ipykernel
$ ipython kernel install --user --name=test

実行

jupyter-labを起動します。

$ test/bin/jupyter-lab

インストールしたカーネルが一覧に表示されるので今回作成したカーネル(test)を選択します。
カーネルはメニュー(Kernel/select kernel)から選択することもできます。
launcher_JupyterLab.png

起動画面(右側)のカーネルがtestになっていることがわかります。
start_JupyterLab.png

仮想環境でインストールしたモジュールをimportするとエラー(ModuleNotFoundError)が発生します。
JupyterLab_ModuleNotFoundError.png

Pythonのパスを表示します。
JupyterLab_syspath_before.png

仮想環境のパスを追加して実行してみます。
importに成功します。
JupyterLab_syspath_after.png
JupyterLab_install_keras.png

リンク

14
17
1

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
14
17