Introduction¶
Learning Objectives¶
Installing Conda (Miniconda)¶
Why Miniconda?¶
Installation¶
Windows¶
curl https://repo.anaconda.com/miniconda/Miniconda3-latest-Windows-x86_64.exe -o .\miniconda.exe
start /wait "" .\miniconda.exe /S
del .\miniconda.exemacOS¶
mkdir -p ~/miniconda3
curl https://repo.anaconda.com/miniconda/Miniconda3-latest-MacOSX-arm64.sh -o ~/miniconda3/miniconda.sh
bash ~/miniconda3/miniconda.sh -b -u -p ~/miniconda3
rm ~/miniconda3/miniconda.shmkdir -p ~/miniconda3
curl https://repo.anaconda.com/miniconda/Miniconda3-latest-MacOSX-x86_64.sh -o ~/miniconda3/miniconda.sh
bash ~/miniconda3/miniconda.sh -b -u -p ~/miniconda3
rm ~/miniconda3/miniconda.shsource ~/miniconda3/bin/activate
conda init --allLinux¶
mkdir -p ~/miniconda3
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O ~/miniconda3/miniconda.sh
bash ~/miniconda3/miniconda.sh -b -u -p ~/miniconda3
rm ~/miniconda3/miniconda.shsource ~/miniconda3/bin/activate
conda init --allVerifying Installation¶
conda --version
conda infoconda config --set auto_activate_base falseUnderstanding Conda Concepts¶
Environments¶
Channels¶
Creating Your First Geospatial Environment¶
# Create a new environment named 'geo' with Python 3.12
conda create -n geo python=3.12
# Activate the environment
conda activate geo
# Install mamba for faster package management
conda install -n base mamba -c conda-forge
# Install essential packages for geospatial programming
mamba install -c conda-forge pygisTroubleshooting Conda¶
conda init cmd.exeEssential Conda Commands¶
Creating and Managing Environments¶
# Basic environment with specific Python version
conda create -n myenv python=3.12
# Environment with multiple packages from the start
conda create -n geoenv python=3.12 numpy pandas matplotlib
# Create environment with packages from specific channels
conda create -n geoenv2 python=3.12 -c conda-forge geopandasconda activate myenvconda deactivateconda env list
# or
conda info --envs# Remove entire environment and all its packages
conda remove -n myenv --all
# Alternative method using env remove
conda env remove -n myenv# Create a copy of an existing environment
conda create -n newenv --clone oldenvInstalling and Managing Packages¶
# Install a package from the main channel
conda install numpy
# Install multiple packages from the main channel
conda install scipy matplotlib seaborn
# Install specific versions
conda install numpy=1.24.0 pandas>=1.5.0# Install without activating the environment
conda install -n myenv pandas
# Useful for setting up environments remotely
conda install -n geoenv -c conda-forge geopandas rasterio# Install from conda-forge (recommended for geospatial packages)
conda install -c conda-forge geopandas# Update all packages in current environment
conda update --all
# Update specific packages
conda update numpy pandas
# Update conda itself
conda update conda# Search for packages
conda search scikit-learn
conda search "*gdal*" # wildcard search
# Get package information
conda search -c conda-forge geopandas --info
# List all installed packages
conda list
# List packages matching a pattern
conda list "*geo*"# Remove a single package
conda remove numpy
# Remove multiple packages
conda remove scipy matplotlib
# Remove packages and their dependencies (if not needed by others)
conda remove numpy --allUsing Mamba (Faster Package Management)¶
# Install mamba in the base environment (do this once)
conda install -n base mamba -c conda-forge# These commands are much faster with mamba
mamba create -n geofast python=3.12
mamba activate geofast
mamba install -c conda-forge geopandas rasterio geemap leafmap
# All conda commands work with mamba
mamba list
mamba update --all
mamba remove geopandasEnvironment Files for Reproducibility¶
# Export all packages and versions
conda env export > environment.yml
# Export with specific name
conda env export -n myenv > myenv.yml# Create environment from exported file
conda env create -f environment.yml
# Create with different name
conda env create -f environment.yml -n newnameIntroducing uv: The Fast Alternative¶
Installing uv¶
curl -LsSf https://astral.sh/uv/install.sh | shpip install uvBasic uv Usage¶
# Navigate to your project directory
cd /path/to/your/project
# Create a virtual environment
uv venv
# Create with specific Python version
uv venv --python 3.12
# Activate the environment (varies by OS)
# On macOS/Linux:
source .venv/bin/activate
# On Windows:
.venv\Scripts\activate# Install packages
uv pip install jupyterlab leafmap
# Install from requirements file
uv pip install -r requirements.txt
# Run Python directly in the environment
uv run python script.py
# Run Jupyter directly
uv run jupyter lab