Quickly Spin-up a Jupyter Notebook virtual environment

Quickly Spin-up a Jupyter Notebook virtual environment

I did this, made it work, and then a week later I had to redo the research because I could not remember how to do it... (so, here we are)

Steps to create a virtual environment, install jupyter notebook and use it


At the time of writing, I have Python 3.11 installed on my Mac, but Jupyter Notebooks do not appear to work with this version of python yet. There are other advantages of using a virtual environment, such as easily being able to install multiple packages and not worrying if they will screw up other scripts that you run from outside a virtual environment.


Create a 'root' directory to house your project files / notebooks and virtual environment

mkdir my_new_project_root

enter the directory

cd my_new_project

I am on macOS, create the virtual environment using python 3.9

python3.9 -m venv my_new_project

activate the virtual environment

source my_new_project/bin/activate

install jupyter notebook

pip3 install jupyter

Install ipykernel

pip3 install ipykernel

Install a Jupyter kernel in your virtual environment

python -m ipykernel install --user --name=my_new_project

launch jupyter notebook using the virtual environment python version

python -m jupyter notebook