Package & Dependency Management

“It worked in Jupyter but crashed on the cluster.” Almost always a dependency problem.

System Package Managers

apt (Debian/Ubuntu)

sudo apt update
sudo apt install htop python3-pip git vim
sudo apt remove htop
sudo apt upgrade
apt search "mesh generator"

yum/dnf (Red Hat/CentOS/Fedora)

sudo dnf install htop
sudo dnf update

brew (macOS)

brew install wget python@3.12
brew upgrade
brew list
brew search paraview

Tip: On a new Linux server: sudo apt update && sudo apt upgrade -y first.

Python: Don’t pip install Globally

# BAD
pip install numpy pandas
# GOOD — use virtual environment

Virtual Environments (venv)

cd my-project/
python3 -m venv venv
source venv/bin/activate
pip install numpy pandas
pip list
pip freeze > requirements.txt
deactivate

Reproducing:

python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt

Key takeaway: Every Python project gets its own virtual environment. Always. No exceptions.

conda / mamba

conda create -n myproject python=3.12
conda activate myproject
conda install numpy scipy matplotlib
conda install -c conda-forge fenics
conda env export > environment.yml
conda env create -f environment.yml
conda deactivate
conda env list
conda env remove -n myproject

Tip: Use conda for compiled scientific packages. Use venv+pip for pure Python. conda-install first, pip-install second.

Checking What’s Installed

pip list
pip show numpy
conda list
which python
python --version

Warning: Always check which python — you might be using system Python instead of your venv.

Locking Dependencies

pip freeze > requirements.txt
conda env export > environment.yml

Try It Yourself

Create an isolated Python venv for a data project, install pandas and requests, freeze the requirements, deactivate, and verify that system Python doesn’t have pandas.

Hint

An ImportError is expected — that’s the point of isolation.

Quiz

Why should you avoid pip install without a virtual environment?

Answer

B) It installs globally, creating version conflicts between projects.