Skip to main content

Creating Python Virtual Environment

Here are some brief instructions for creating a Python virtual environment (venv) and generating a custom Jupyter kernel based on the venv:

Logon to your Nero instance

$ gcloud compute ssh --zone=us-west1-a cdoane-rstudio-sas-stata --project srcc-nero-dev -- -L 8080:localhost:8080

1. Become jupyter user

sudo -u jupyter -i

2. Create Virtual Environment (venv)

/opt/jupyter/bin/python3 -m venv cdoane-pyth-env-new

3. Install ipykernel package in venv

./cdoane-pyth-env-new/bin/pip3 install ipykernel

4. Create custom kernel based on venv

./cdoane-python-venv/bin/python3 -m ipykernel install --user --name cdoane-pyth-env-new --env PATH '/srv/jupyter/cdoane-python-venv/bin:${PATH}'

Now move over to your Jupyter web interface

You should see a new launcher button for a Python kernel called cdoane-pyth-env-new . You can then install additional packages into the venv either from a terminal or from a notebook launched with the new kernel:

1. Install additional packages in venv from terminal

./cdoane-pyth-env-new/bin/pip3 install pandas

2. Install additional packages in venv from notebook

!pip3 install pandas