Skip to main content

How to create a local Python environment for your WEkEO projects

Let's see the steps to create a local Python environment using Mamba, the most recommended method for your WEkEO projects.

Written by Alexandre

Context


WEkEO provides different training materials, with notebooks requiring a different set of Python and R packages, whether the case study is about heatwave, windrose, upwelling, etc.

By applying the method described in this article, you will have a single and unique environment from which you can execute any of our training notebooks.

As we do not recommend installing packages system-wide, we present below two easy ways to create an isolated Python environment using Mamba, a Command Line Interface (CLI) tool acting as a drop-in replacement for Conda that is generally faster and better at resolving dependencies.

What is Conda? (click me)

Conda is a multiplatform package, dependency, and environment management for any language - Python, R, Ruby, Lua, Scala, Java, JavaScript, C/ C++, FORTRAN, and more.

It does not require any administrative permission on the machine to be installed and it can be very storage-friendly if you follow this (thanks to Miniforge).

Before starting


If you already have any of the following packages, venv, pipenv, pyenv, pipx, poetry, virtualenv, then there is a good chance you already know how to create an isolated environment, and thus feel free to use only the content of this YAML file to extract the list of required packages.

If you already have Anaconda or Miniconda on your machine, please jump directly to the creation of the environment, replacing the word mamba by conda in the shown commands.

(Optional but recommended) Download and install Miniforge


⚠️ This step should be followed only if you don't have any of the following utilities on your machine: conda, anaconda, miniconda, venv, pipenv, pyenv, pipx, poetry, virtualenv. Otherwise, you should jump to the creation of the environment adapting commands to your utility.

Miniforge is the installer we recommend to get mamba on your machine. Download and install Miniforge for your operating system:

📌 Note: for this guideline, we chose the Miniforge3-Windows-x86_64 installer because we are running on Windows 11

Once it is installed, a new software is available on your machine: Miniforge Prompt 😃

It's the terminal you can now use to create your environments. When you open it, you will see that your base environment is activated with Python already available. You can run this command to see the version of Python:

python --version

Finally, let's move to the next step but please be informed that you could create an environment for any Python version you like:

mamba create --name my_environment_python_3.12 python==3.12

💡WEkEO Pro Tip: if you are used to Anaconda or Miniconda, you already know Mamba since you just need to replace conda by mamba in the commands!

Create your own local Python environment


To create your own local Python environment, compatible with our training materials, either:

  • you already have any of the following utilities venv, pipenv, pyenv, pipx, poetry, virtualenv: Then you should create the commands tailored to your utility, based on the below commands.

  • you already have conda (thanks to Anaconda or Miniconda): Then you can run the next commands but use your usual terminal and replace the word mamba by conda.

  • you have just installed Mamba: Then you can simply copy and paste the next commands, as is.

Download the YAML file

Download the file wekeo_env_py3.13.yml that contains the specific packages that will be included in the environment you are going to create.

Open the terminal

  1. Open the Miniforge Prompt

  2. Move to the directory where you have saved the wekeo_env_py3.13.yml file.
    For example:

cd "%USERPROFILE%\Downloads"

Create the environment

Create the new virtual environment as specified in the file wekeo_env_py3.13.yml, by running in your Miniforge Prompt:

mamba env create --file wekeo_env_py3.13.yml

📌 Note: the creation process could take some time. In addition, it could generate some warning messages. However, you should then be able to activate and use the environment normally.

Activate the environment

Once the creation is successful, it is permanent. As a consequence, the only action that needs to be repeated each time you boot your session is the activation of the environment. Indeed, by default, your terminal will be set to run the base environment.

You can activate the environment by running in the Miniforge Prompt:

mamba activate wekeo_env_py3.13

(Optional but recommended) Register the environment as a kernel

To use this environment in a notebook, you must first add it to your available kernels, as shown below:

python -m ipykernel install --user --name wekeo_env_py3.13 --display-name wekeo_py3.13

Then, restart your notebook to see the new kernel appear. This should only be done once per machine because it is, as the creation, persistent after a reboot.

And tadaaaa! 😃

You can now run any WEkEO training materials and use the HDA API Python client on your computer using this new environment!

For example, you can check the version of the HDA by running:

conda list hda

What's next?


Additional resources can be found in our Help Center. If you need further help or have any feedback, feel free to contact us via the chat at the bottom right corner of the page.

Did this answer your question?