Skip to content
Virtual environments

Virtual environments

mamba lets you install Python packages for a class or project without affecting other people.

Create an environment

  1. Log in to a lab or compute machine.
  2. Create an environment (pick any short name instead of myproject):
mamba create -n myproject python=3.12 pandas

Type y if it asks to confirm.

It may take a minute or two to create your new environment, depending on what packages you install and whether they are already cached. If it prints Linking ..., it may pause briefly with little new output while it finishes setting up files on shared scratch.

  1. Turn the environment on:
mamba activate myproject

Your prompt should show (myproject). Now python uses the packages in that environment.

  1. When you are done:
mamba deactivate

Day-to-day use

mamba activate myproject          # start working
python your_script.py
mamba install numpy               # add a package (while activated)
mamba deactivate                  # stop working
mamba env list                    # see your environments

Creating an environment takes the longest. Activating and using it later is fast. The same environment works on other lab/compute machines after it exists.

Where your environments live

Environments are stored under your scratch space, not your home directory:

/home/scratch/YOUR_USERNAME/mamba/envs/

That is why they follow you from one lab/compute machine to another.