Jupyter Notebook in a virtual environment (virtualenv)

Emmanuel

I love Jupyter Notebook. I use it all the time.

I’ve been looking to use it with a Django App to profile timing and memory usage of specific function but first I had to get it running in a virtual environment.

Make sure you have virtualenv installed

pip install virtualenv

Create a virtual environment

Note: I like to use a . in front of my virtual environments so the folder is hidden.

virtualenv .venv

Get inside the environment

source .venv/bin/activate

or in shorthand

. .venv/bin/activate

You can verify quickly you are in the environment by running which python which will return the path of the python executable in the environment if all went well

which python
> xxxxx/.venv/bin/python

Install a Jupyter kernel

This will install a kernel inside the environment, to use to run in the Jupyter notebook there:

ipython kernel install --user --name=.venv

Run Jupyter, and select the .venv kernel to run the notebook

jupyter notebook

Emmanuel

Written by

Emmanuel

Product Manager, Solution Architect, Entrepreneur, passionate about making sense of data.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade