4. Setting up a local Python environment with Mamba

4.3. Create a Python environment

Before setting up a new Python environment, let's review the advantages of virtual environments and why they are crucial for Python projects (from Christian Mills tutorial).

  • Isolation of Dependencies: Virtual environments create isolated spaces for each project, allowing developers to install and manage different package versions without conflicts. This isolation ensures that the specific dependencies required for one project do not interfere with or break the dependencies of another project.
  • Easier Project Management: Virtual environments help streamline project management by maintaining separate configurations for different projects. Developers can replicate or share project environments with team members, ensuring consistent behavior across various machines. Shareable project environments help developers collaborate, troubleshoot, and deploy projects.
  • Simplified System Maintenance: Using virtual environments helps developers avoid cluttering their system-wide Python installation with numerous packages and varying versions. System maintenance is cleaner as developers can easily add, update, or remove packages within individual project environments without affecting other projects or the system as a whole.

Let's create an environment with the name tutorials and install the packages pcraster, qgis, matplotlib, jupyter lab, pycrs, numpy and git that we need for the tutorials.

1. At the Miniforge Prompt type the following command and press <Enter>:

mamba create --name tutorials pcraster qgis matplotlib jupyterlab pycrs numpy git 
Mamba will look for the packages.


2. Confirm the changes by typing Y.


When the packages are downloaded and installed Mamba will tell you how to activate the environment:


3. Activate the tutorials environment by typing:

mamba activate tutorials
You'll use this command in the future every time you start a new Miniforge prompt in order to use the tutorials environment.

In the next subchapter you'll learn how to clone the repository with tutorials from the GitHub repository.