Jupyter notebook inside a virtual environment

Follow these steps to run a jupyter notebook inside a python virtual environment where you can install all the packages you need for your project.

Initial setup

  1. Login to open ondemand - https://utc-ondemand.research.utc.edu
  2. Select "Jupyter Notebook" from the "Interactive Apps" menu
  3. Fill out the form:
    • Partition: "general" for CPU only jobs, or "gpu" for GPU enabled jobs
    • Number of nodes: 1
    • Number of cores per node: 8
    • Number of GPUs per node: 1 or 2 only if you used "gpu" for the partition
    • Number of hours: anything up to 120
  4. After filling out the form, click "Launch"
  5. After the session has started, click "Connect to Jupyter"
  6. In the new window where the jupyter notebook is, click the "New" button in the top right corner and select "terminal"
  7. In the terminal window that opens, enter the following commands. I'm using "jupyter-tensorflow" as the project name, but you can use whatever you want. Just make sure to use that name everywhere you see my example name.
    module load python/3.10
    python -m venv jupyter-tensorflow
    cd jupyter-tensorflow
    source bin/activate
    pip install ipykernel
    python -m ipykernel install --user --name=jupyter-tensorflow
    pip install <other things you need, like tensorflow>
  8. Once everything is installed, close the terminal window and go back to the jupyter window and refresh the window
  9. Click the "New" button in the top right corner and you should see your new virutal environment in the list. Click that.
  10. The new window that opens up is running inside the virtual environment and will have access to all the packages you installed in it.

In the future, if you want to start a new project using this virtual environment

  1. Login to open ondemand - https://utc-ondemand.research.utc.edu
  2. Select "Jupyter Notebook" from the "Interactive Apps" menu
  3. Fill out the form:
    • Partition: "general" for CPU only jobs, or "gpu" for GPU enabled jobs
    • Number of nodes: 1
    • Number of cores per node: 8
    • Number of GPUs per node: 1 or 2 only if you used "gpu" for the partition
    • Number of hours: anything up to 120
  4. After filling out the form, click "Launch"
  5. After the session has started, click "Connect to Jupyter"
  6. In the new window where the jupyter notebook is, click the "New" button in the top right corner and select your virtual environment
  7. Do your work in the new window that opens up

If you want to resume work on a project that uses the virtual environment

  1. Just open the file you were working on the last time and it will load up in the virtual environment

If you ever decide to delete the virtual environment

  1. Login to open ondemand - https://utc-ondemand.research.utc.edu
  2. Select "Jupyter Notebook" from the "Interactive Apps" menu
  3. Fill out the form:
    • Partition: "general" for CPU only jobs, or "gpu" for GPU enabled jobs
    • Number of nodes: 1
    • Number of cores per node: 8
    • Number of GPUs per node: 1 or 2 only if you used "gpu" for the partition
    • Number of hours: anything up to 120
  4. After filling out the form, click "Launch"
  5. After the session has started, click "Connect to Jupyter"
  6. In the new window where the jupyter notebook is, click the "New" button in the top right corner and select "terminal"
  7. In the terminal window that opens, enter the following commands. I'm using "jupyter-tensorflow" as the project name, but you can use whatever you want. Just make sure to use that name everywhere you see my example name.
    jupyter kernelspec remove jupyter-tensorflow
    rm -r -f jupyter-tensorflow