Python Environment: Miniforge¶
Miniforge is a powerful package management system that provides fast and reliable installation of scientific packages and their dependencies.
What is Miniforge?¶
Miniforge is a distribution of the conda package manager that uses the fast mamba solver instead of the traditional conda solver. It includes:
Mamba: A fast, cross-platform package manager
Conda: The classic conda package manager
Python: A Python interpreter
Essential packages: numpy, pandas, scipy, etc.
Why Choose Miniforge?¶
Speed: Mamba is significantly faster than conda (often 10-100x faster)
Reliability: Better dependency resolution
Cross-platform: Works on Windows, macOS, and Linux
Large ecosystem: Access to millions of packages via conda-forge
Environment management: Create isolated environments for different projects
Installation¶
Download Miniforge¶
Visit the official download page: https://github.com/conda-forge/miniforge
Choose the installer for your operating system:
Windows: Download
Miniforge-Windows-x86_64.exemacOS: Download
Miniforge-MacOSX-x86_64.sh(Intel) orMiniforge-MacOSX-arm64.sh(Apple Silicon)Linux (WSL): Download
Miniforge-Linux-x86_64.sh
Install on Windows¶
Run the downloaded
.exefileFollow the installation wizard
Choose installation location (recommended:
C:\Users\<username>\miniforge3)Check “Add Miniforge to PATH” (optional, but recommended for beginners)
Complete installation
Note
I recommend using Windows Subsystem for Linux (WSL) for a more Unix-like experience when working with Miniforge on Windows. Please see the WSL setup guide for more details.
Install on macOS/Linux (including WSL)¶
Open Terminal
Navigate to download directory:
cd path/to/downloads
Run the installer script:
sh Miniforge-*.shFollow the prompts:
Press Enter to read the license
Type
yesto acceptChoose installation location (default is recommended)
Type
yesto initialize Miniforge
Restart your terminal or run:
exec $SHELL
Verify Installation¶
After installation, verify it works:
mamba --version
conda --version
You should see version numbers for both mamba and conda.
Basic Usage¶
Understanding Environment Isolation¶
One of Miniforge’s most powerful features is environment isolation. This is crucial for beginners to understand and use properly.
Why Do You Need Environment Isolation?¶
Imagine you’re working on multiple projects:
Project A: Uses TensorFlow 2.10 and Python 3.9
Project B: Uses PyTorch 2.0 and Python 3.10
Project C: Uses scikit-learn for simple machine learning
Without environments:
Installing different versions of the same package can cause conflicts
One project’s requirements might break another project
You can’t easily share or reproduce your setup
System Python gets cluttered with packages
With environments:
Each project has its own isolated space
Different projects can use different package versions
Easy to switch between projects
Clean, reproducible setups
How Environment Isolation Works¶
Each conda environment is like a separate Python installation:
Separate package directories: Packages are installed in isolated locations
Independent Python versions: Each environment can have different Python versions
Isolated dependencies: Package conflicts are contained within each environment
Clean separation: Removing an environment doesn’t affect others
Real-World Examples¶
# Data Science Environment
mamba create -n data-science python=3.9
mamba activate data-science
mamba install jupyter pandas numpy matplotlib seaborn scikit-learn
# Deep Learning Environment
mamba create -n deep-learning python=3.10
mamba activate deep-learning
mamba install tensorflow pytorch jupyter
# Computer Vision Environment
mamba create -n cv python=3.11
mamba activate cv
mamba install opencv pillow scikit-image
Environment Management Best Practices¶
Use descriptive names:
mamba create -n web-dev-2024 python=3.11Keep environments focused: One environment per project or purpose
Document your environments: Save environment specifications
Regular cleanup: Remove unused environments
Version control environments: Include
environment.ymlin your projects
Switching Between Environments¶
# Check current environment (shows * next to active)
mamba env list
# Activate an environment
mamba activate my-project
# Check which Python is being used
which python
python --version
# Deactivate current environment
mamba deactivate
# Deactivate all environments (back to base)
mamba deactivate
Update Miniforge¶
Keep your installation updated:
mamba update mamba
mamba update conda
Create a New Environment¶
Create isolated environments for different projects:
# Create a new environment with Python 3.10
mamba create -n myenv python=3.10
# Activate the environment
mamba activate myenv
# Deactivate
mamba deactivate
Install Packages¶
Install packages in your environment:
# Install a single package
mamba install numpy
# Install multiple packages
mamba install numpy pandas matplotlib
# Install from a specific channel
mamba install -c conda-forge tensorflow
List Environments and Packages¶
# List all environments
mamba env list
# List packages in current environment
mamba list
# List packages in specific environment
mamba list -n myenv
Remove Environments and Packages¶
# Remove a package
mamba remove package_name
# Remove an entire environment
mamba env remove -n myenv
Using Jupyter Notebook/Lab¶
After installation:
# Activate your ML environment
mamba activate ml
# Start JupyterLab
jupyter lab
# Or start Jupyter Notebook
jupyter notebook
This will open a browser window where you can create and run notebooks.
Environment Management Best Practices¶
Use environments liberally: Create separate environments for different projects
Keep environments small: Only install what you need
Update regularly: Keep packages updated for security and performance
Export environment: Save environment specifications for reproducibility
# Export environment to file
mamba env export > environment.yml
# Create environment from file
mamba env create -f environment.yml
Getting Help¶
Official documentation: https://mamba.readthedocs.io/
Conda documentation: https://docs.conda.io/
Community forums: https://github.com/mamba-org/mamba