Skip to content

Instantly share code, notes, and snippets.

@mjkrause
Last active August 2, 2019 16:11
Show Gist options
  • Save mjkrause/169f72c81515637ec927e026761f8e31 to your computer and use it in GitHub Desktop.
Save mjkrause/169f72c81515637ec927e026761f8e31 to your computer and use it in GitHub Desktop.
Sourcing a virtual environment inside a Jupyter Notebook

Running Jupyter Notebook inside the virtual environment

You want to activate a virtual environment when running a Jupyter notebook using Python. In a terminal create a virtual environment, e.g., virtualenv --python=python3.6 .venv, then source that environment. Besides installing any required package and Jupyter (pip install --upgrade jupter) you need to install ipykernel, the IPython backend:

pip install ipykernel
python -m ipykernel install --user --name=.venv

Next launch Jupyter. In the upper right corner go to Kernel -> Change Kernel. You should see .venv in the drop down. Select it, restart the kernel, et voila...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment