In this note, we will see how to set up a juypter notebook using conda virtual environment. The significant advantage of using a virtual environment is that it does not alter/update existing python packages used by other projects/assignments. So creating the Python Virtual Environment for individual project work is always beneficial. Hence, we will learn how to create and install all the packages within conda virtual environment.
Introduction
It has been assumed that some python distribution is already installed in our system. These distributions could be anaconda framework, miniconda, or native python with conda package manager.
Step 1: Creation of conda virtual environment
While creating a virtual environment, we can specify the python version, which is always beneficial. However, it is not mandatory to select the python version. Here, venv_name could be anything, but appropriate name is always helpful for identifying the environment. We can list all the available conda environments by using conda env list command.
conda create -n venv_name python=3.9.5
Step 2: Activation of conda virtual environment
Using the below command, we can activate the virtual environment. Once we start the virtual environment, whatever packages we install will remain within the virtual environment.
conda activate venv_name
We will install two different packages, and these are ipykernel and jupyter.
IPython is an interactive command-line terminal for Python. It offers an enhanced read-eval-print loop (REPL) environment particularly well adapted to scientific computing. Where as, the Jupyter Notebook is the original web application for creating and sharing computational documents. It offers a simple, streamlined, document-centric experience.
conda install ipykernel conda install jupyter
Step 4: Making a connection between ipykernel and jupyter notebook
Once we execute the below command, we will create a notebook using any of the existing available environments. Further, we can list all the kernelspec environment using jupyter kernelspec list
command and delete unused kernel spec environment using jupyter kernelspec remove venv_name
command.
python -m ipykernel install --user --name venv_name
Step 5: Opening of Jupyter notebook
Using the below command, we can start jupyer notebook. It usually select default browser to open a new notebook.
jupyter notebook
Step 6: Deactivation of conda environment
After completing the task, either we can close the terminal or deactivate conda environment usingconda deactivate venv_name
command. I hope it will be helpful to install and run the jupyter notebook using python anaconda or miniconda framework.
References
- https://ipython.readthedocs.io/en/stable/install/kernel_install.html
- https://conda.io/miniconda.html
- https://notepub.io/notes/data-science/foundations-of-data-science/data-science-setting-up-a-virtual-environment-for-jupyter-notebook/
2,207 total views, 1 views today