How to Execute Python Script in Jupyter Notebook using a Specific Virtual Environment, How to list and remove kernels from Jupyter Notebook


# Suppose you are in an activate virtualenv named py2env

(py2env)$ 

# Then install jupyter within the active virtualenv
(py2env)$ pip install jupyter

# jupyter comes with ipykernel, but somehow you manage to get an error due to ipykernel, then for reference ipykernel package can be installed using:
(py2env)$ pip install ipykernel

# set up the kernel
(py2env)$ python -m ipykernel install --user --name py2env --display-name "Python2 (py2env)"

# Now we can start jupyter notebook
(py2env)$ jupyter notebook




How to list kernels of Jupyter Notebook

If we want to check the list of kernels in our Jupyter Notebook, and remove afterwards.

$ jupyter kernelspec list
This will give you a list of kernels as follows
Available kernels:
  hbnn            /home/parklize/.local/share/jupyter/kernels/hbnn
  iswctest        /home/parklize/.local/share/jupyter/kernels/iswctest
  milvus          /home/parklize/.local/share/jupyter/kernels/milvus
  py3.6           /home/parklize/.local/share/jupyter/kernels/py3.6
  py3.7tf2.3.0    /home/parklize/.local/share/jupyter/kernels/py3.7tf2.3.0
  py3.7tf2.4.1    /home/parklize/.local/share/jupyter/kernels/py3.7tf2.4.1
  pymc            /home/parklize/.local/share/jupyter/kernels/pymc
  xai             /home/parklize/.local/share/jupyter/kernels/xai
  python3         /home/parklize/anaconda3/envs/pymc_env/share/jupyter/kernels/python3

How to remove a kernel of Jupyter Notebook

If we want to remove one of them, for example, the following command removes the hbnn kernel.

$ jupyter kernelspec remove hbnn

No comments:

Post a Comment