Configuration for Jupyter Notebook

Jupyter Notebook is commonly used with Python in data science projects. You can install a virtual environment using venv or pipenv and configure the ActiveState Platform Security & Compliance plugin to scan packages you use in Jupyter Notebook.

The basic steps are:

  1. Create your project folder, and then create and activate your virtual environment.
  2. Install and configure the Security & Compliance plugin.
  3. Link your virtual environment to the Jupyter Notebook kernel and start the Jupyter Notebook server.

Prerequisites:

  1. ActivePython is installed and configured
  2. You have downloaded the Security & Compliance plugin from the ActiveState Platform. For more information see steps 1-4 in Installing the Security & Compliance plugin.
  3. You have set up an identity and created the activestate.config file, and you have saved the file to an appropriate location on the computer that will run the Jupyter Notebook server. For example, the \etc directory or the project directory. For more information, see Configuring Identities.

Configuring Jupyter Notebook with venv

mkdir ~/notebooks && cd $_
python3 -m venv .venv --system-site-packages
source .venv/bin/activate
pip3 install ActiveState-SecurityScanner-0.5.5.tar.gz

When you create your virtual environment with the --system-site-packages flag you have access to all of the needed packages to run Jupyter Notebook. You can reference your activated environment as .venv. You need to use this name to register the virtual environment with Jupyter Notebook and start the Jupyter Notebook server.

python3 -m ipykernel install --user --name=.venv
jupyter notebook

When you create a new notebook, you have the option to create it for your virtual environment (.venv) instead of choosing the default python3 option. You can also change the kernel used by existing notebooks by selecting Kernel > Change Kernel > .vnev from the Jupyter Notebook menu.

Configuring Jupyter Notebook with pipenv

Pipenv ships with recent releases of ActivePython. For earlier releases, you can install it with pip3 (Python 3.x) or pip (Python 2.x).

pip3 install --user pipenv

You might need to add the user location to your path. To find it run python -m site --user-base and add bin to the result.

mkdir ~/notebooks && cd $_
pipenv --python="/home/parallels/AP354/bin/python3" --site-packages install
pipenv install ActiveState-SecurityScanner-0.5.5.tar.gz
pipenv shell

When you activate the shell the name of the virtual enviroment is displayed in brackets at the start of the command prompt line. In the following example notebooks_pipenv-07CRs3n_ is the virtual environment name:

(notebooks_pipenv-07CRs3n_) parallels@parallels-vm:~/notebooks_pipenv$

When you create your virtual environment with the --site-packages flag you have access to all of the needed packages to run Jupyter Notebook. You can reference your activated environment as notebooks_pipenv-07CRs3n_. You need to use this name when you register the virtual environment with Jupyter Notebook and start the Jupyter Notebook server.

python -m ipykernel install --user --name=notebooks_pipenv-07CRs3n_
jupyter notebook

When you create a new notebook, you have the option to create it for your virtual environment (.venv) instead of choosing the default python3 option. You can also change the kernel used by existing notebooks by selecting Kernel > Change Kernel > notebooks_pipenv-07CRs3n_ from the Jupyter Notebook menu.