Computer Environments Practical Exercises

These exercises accompany the Computer Environments module. They walk you through installing venv and micromamba, exploring environment isolation, and observing how package managers can silently alter dependencies.


Exercises developed by Jared Johnson

Exercise 1 — Installing Micromamba and Venv

This section walks through installing venv and micromamba for use in later sections.

Installing Micromamba

The steps below will install micromamba into your $HOME directory. Skip to Installing Venv if you plan to use an existing installation of micromamba, mamba, conda, or miniconda.

1.1 Install Micromamba

Check if micromamba is installed:

micromamba --version

Install micromamba, if needed (no sudo required):

"${SHELL}" <(curl -L micro.mamba.pm/install.sh)

Reset your shell:

source ~/.bashrc

1.2 Add bioconda channel (optional)

micromamba config append channels bioconda

Installing Venv

This process checks whether venv is available via your system-wide Python. If not, you will install Python (with venv) inside a micromamba environment (suitable for non-root users).

1.3 Check if venv is installed

python3 -m venv --help

1.4 Install Python with venv via micromamba (if needed)

micromamba create -n py311_env python=3.11

Exercise 2 — Environment Isolation

This exercise highlights differences in how venv and micromamba create isolated environments.

Attempt each step below before exposing the answer.

Getting Started

2.1 Record the path to your base python3 executable

realpath "$(command -v python3)"
Record answer below

Venv Environments

2.2 Create and activate a new venv

python3 -m venv venv_test_1
source venv_test_1/bin/activate

2.3 Determine Python executable location

realpath "$(command -v python3)"
Record answer below

Question 2.5.1 Is this the same as the python3 path in step 2.1?

Your venv uses the same Python executable as your base install.

2.4 Deactivate environments

deactivate
micromamba deactivate

You should now be in your base environment.

Conda / Mamba Environments

The following should be performed from your base environment, not the py311_env created in Exercise 1. You can return to your base environment using micromamba deactivate.

2.5 Create and activate a new micromamba environment

Create a new micromamba environment called mamba_test_1:

micromamba create -n mamba_test_1 python=3.11

Activate your new environment:

micromamba activate mamba_test_1

2.6 Determine the location of your Python executable again

realpath "$(command -v python3)"
Record answer below

Question 2.6.1 Is this the same as the python3 path in step 2.1?

Your mamba_test_1 environment should use a different Python executable than recorded in step 1. This is because Conda and Mamba install a new Python executable for each environment, making it independent from your base installation.


Exercise 3 — Silent Changes

This exercise shows how pip can silently alter already-installed packages.

Testing a new script (venv)

3.1 Download the test script and data

wget https://github.com/CDCgov/id-bioifx-workshop/raw/36941cd352dc7282ad26583389322549c362e8ec/practical/computer_env/pt2_script.py
wget https://github.com/CDCgov/id-bioifx-workshop/raw/refs/heads/lmc_jdj/practical/computer_env/pt2_dataset-1.csv
wget https://github.com/CDCgov/id-bioifx-workshop/raw/refs/heads/lmc_jdj/practical/computer_env/pt2_dataset-2.csv



3.2 Create and activate venv_test_2

python3 -m venv venv_test_2
source venv_test_2/bin/activate

3.3 Install pinned dependencies

pip install "numpy<2.0" "pandas==1.5.0"

3.4 Run script

python3 pt2_script.py

If successful, it should print a summary of three dataframes: Dataframe 1, Dataframe 2, and Combined Dataframes.

Question 3.4.1 Did the script work?

The disruption (venv)

3.5 Install scanpy with pip

One of the other bioinformaticians in your lab is having trouble installing the Python module scanpy. They ask if you are able to install it on your machine.

pip install scanpy

3.6 Back to your test script

With that out of the way, you get back to running your test script:

python3 ./pt2_script.py

Question 3.6.1 Did the script work?

If not, why?

Record answer below

Check your pandas version using:

pip list | grep pandas

Does this match the v1.5.0 you installed in step 3?

pip can silently change the version of existing modules (in this case, pandas) when installing new packages (in this case, scanpy). This can break dependencies and render older scripts unusable (in this case, pt2_script.py)!

Testing a new script (micromamba)

The following should be performed from your base environment, not the py311_env created in Exercise 1. You can return to your base environment using micromamba deactivate.

3.7 Create and activate a new micromamba environment

Use micromamba to create and activate a new environment called mamba_test_2.

micromamba create -n mamba_test_2 python=3.10 -y
micromamba activate mamba_test_2

3.8 Install the pinned dependencies with micromamba

Install the same dependencies as before (pandas v1.5.0 and numpy < v2.0), but with micromamba.

micromamba install -y -c conda-forge "numpy<2.0" "pandas=1.5.0"

3.9 Run the test script

python3 ./pt2_script.py

Question 3.9.1 Did the script work?

The disruption (micromamba)

3.10 Install scanpy with micromamba

Your co-worker is back and they want you to try installing scanpy again, but this time using micromamba.

Hint: Inspect the installation summary before confirming [Y] or denying [n] the installation.

micromamba install -c conda-forge -c bioconda scanpy

Question 3.10.1 Did you confirm [Y] or deny [n] the installation? Why?

Record answer below

3.11 Run the test script

Try the test script one last time after making your decision about scanpy:

python3 ./pt2_script.py

Question 3.11.1 Did the script work?

Question 3.11.2 Do you regret your decision from step 3.10?

micromamba warned us that installing scanpy would require updating to a new version of pandas. This allowed us to avoid silently breaking the pandas v1.5.0 dependency of pt2_script.py.