Skip to main content

Configuring Jupyter Notebook in a Virtual Environment

Step 1: Install Jupyter Notebook

With the virtual environment activated, install Jupyter Notebook:

pip install jupyter

Step 2: Start Jupyter Notebook

Start Jupyter Notebook by running:

jupyter notebook

This will open the Jupyter Notebook interface in your default web browser.

Step 3: Creating and Using a Kernel for Your Virtual Environment

To use your virtual environment in Jupyter Notebook, you need to create a new kernel:

Install ipykernel:

pip install ipykernel

Create a new kernel:

python -m ipykernel install --user --name=venv --display-name "Python (venv)"

Here, venv is the name of the kernel, and "Python (venv)" is the display name that will appear in the Jupyter Notebook interface.

In Jupyter Notebook, you can now select the "Python (venv)" kernel from the kernel options.

Deactivating the Virtual Environment

When you're done working in the virtual environment, you can deactivate it by running:

deactivate

Conclusion

You have successfully set up a Python virtual environment and configured Jupyter Notebook to work within this environment. This setup helps you manage dependencies and maintain isolated environments for different projects.