How to join conda env into jupyter notebook
來源:
- ref. medium
- ipython doc
- https://jupyter.org/install
安裝 Jupyter (Jupyter Lab, Jupyter Notebook)
首先要有安裝 jupyter notebook/lab,兩者挑一個安裝即可,
我建議用 conda 建一個只用來建制 Jyputer Server 的環境, 以方便管理
(anaconda 已內建、miniconda 要自己裝)
Jupyter Notebook (類似 google colab)
install the classic Jupyter Notebook
To run the notebook:
JupyterLab (有整合 command line)
Install JupyterLab with pip:
To run JupyterLab:
可透過已下命令,可於任意虛擬環境查看目前 jupyter 已連動的 kernel
將指定的 comda python 環境加進 jupyter kernel
- Create a Conda environment.
1
| conda create --name <myenv>
|
or create a tensorflow with gpu env:
1
| conda create -n <myenv-gpu> python=<version> tensorflow-gpu
|
- Activate <myenv>
install any package you need in this environment.
- Set this conda environment on your jupyter notebook, to do so please install ipykernel. (install in this myenv)
1 2 3
| conda activate myenv conda install pip conda install ipykernel
|
可透過已下命令,可查看目前虛擬環境允許被 jupyter 連動 (當啟動 jyputer notebook 會自動帶入此環境為 jyputer kernel)
- Install a
Python environment Kernel
in a myenv.
1 2
| conda activate myenv python -m ipykernel install --user --name <this-myenv-name> --display-name "name-you-want-show-in-notebook"
|
當然,你也可以為其他虛擬環境增加 ipykernel (使 jupyter notebook 可以使用此 env 作為 kernel)
1 2
| conda activate other-env python -m ipykernel install --user --name <this-env-name> --display-name "Python (other-env)"
|
移除 ipykernel
- 列出目前 jupyter 追蹤的虛擬環境與其路徑 (光是刪除 conda env 是無效的,還必須將其從清單中移除)
移除對應的 env-name
1
| jupyter kernelspec remove <myenv>
|