Python related Problems
Introduction to conda / micromamba
What is conda ?
This is the package manager for the anaconda or miniconda distribution of Python. It allows to install packages and create environments and much much more. However, mostly you will use it to install packages and create environments for your code. It is slow. link
What is micromamba ?
This is a replacement package manager for Python that is independent from a distribution and can be used to create fuly independent python environments with just the micromamba executable as strting point. link
Conda environment | |
---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
|
What should I use?
It is recommended to use micromamba, which is way faster than conda. It has a smaller footprint and it works almost identical as conda. It is a c++ replacement of conda/mamba.
install packages
There are sometimes different versions available with different build options as well, you can use the search function (micromamba search
) to get an understanding of what versions and builds are available.
micromamba environment | |
---|---|
1 2 3 4 5 6 |
|
Looking for Python packages/names?
Search here: conda-forge or PyPI
Creating a common environment for most users
It is more efficient to use a common environment, that is present on all servers and just add your few additions, then to spawn a full new copy of everything. It is very efficient to create an environment file and reuse these or build on top of an existing environment.
There are three environments present all department servers:
- Default Python environment present with a jupyterhub
- The Magic Python Kernel (definition)
- The RTTOV Python Kernel (container definition on Phaidra)
Create the Magic Kernel | |
---|---|
1 2 3 4 5 6 |
|
Q: Installing Cartopy or any other module based environment?
The user needs to load geos
and proj
modules and then install the package via
pip install --user cartopy
or create an environment and install there.
Installing from conda-forge
is also possible, without loading any modules.
e.g. micromamba install -n <my-env> -c conda-forge cartopy
in a conda environment. This will install a lot of files and libraries.
Go to: Cartopy Installation Notebook
Q: Load Modules into the current Notebook Environment?
The Idea is to create a load_modules_into_jupyter.conf
file in your home directory asking for modules to be loaded when ther kernel is launched.
Please note that the file needs an empty line at the end
Go to: Modules loaded in Kernel
Q: How to create a user environment?
The idea is to install a micromamba or virtual environment and use that as a kernel for your notebooks. Please note the solution for cartopy
Go to: Conda/Virtual Environment (updated 2025/06)
Q: The Notebook server on the TeachingHub won't start?
This usually happens because of an old configuration. Try to remove ~/.jupyter
on SRVX1. Deprecated
Go to: Teaching-Hub Spawn
Q: Executing Python code on remote servers?
The idea is to launch an interactive IPython console on your computer (Linux or Mac, not sure about Windows) with a kernel on the server.
Go to: Remote IPython Kernels
Q: What Python IDE to use with remote kernels?
There are a lot of different ways to develop in python.
Some are:
- Visual Studio Code
- PyCharm
- Editors like Emacs, Sublime, Vim,...
- Jupyter Notebooks and Lab e.g. on Jupyterhub@srvx1
or jupyterhub@jet
and atom
. This is simple editor available on any platform and it can be extended with packages to become a full grown IDE with the power of open source.
Q: How to restore a conda environment?
Ever needed to backup a conda environment or copy from a colleague or designing one by hand to give to others?
Go to: Save/Restore conda environment
Q: How to get the dask dashboard working on Jupyterhub?
You just need to add a configuration option and then you can open the Dashboard in any Jupyterhub. Works on SRVX1 and JET.
Go to: Fix Dask Dashboard
Q: How to profile memory and exeution time of functions?
If you need to get a better understanding of you functions memory and execution time, try these profiling options.
Go to: Profile
Q: How to read BUFR files with python?
ECMWF created a python package that helps to read BUFR messages via ECCODES into pandas DataFrame.
Go to: BUFR
Q: How to read ODB files with python?
ECMWF created a python package that helps to read ODB messages via ODC or pure Python into pandas DataFrame.
Go to: ODB
Q: How to retrieve data from MARS in python?
ECMWF has created a package that allows to retrieve data from MARS, easily.
Go to: MARS
Q: How to retrieve ERA5 from CDS and plot in Magics?
It is very easy to download and plot ERA5 data, using cdsapi and Magics.
Go to: Magics
Q: How to ignore user site packages?
When using python it is possible to have multiple site, where packages can be installed. the default is to use the path from the python interpreter and a user site.
Bash | |
---|---|
1 2 3 4 5 6 7 |
|
this shows that there is a user site in your HOME directory for that python version. Python will always look for a directory for it's own version.
You can disable that by altering the sys.path
(python type list) manually or using an environment variable (export PYTHONNOUSERSITE=1
).
Bash | |
---|---|
1 2 3 4 5 6 7 8 9 |
|
Q: How to use pipelines for building and publishing packages?
Use a .gitlab-ci.yml file to automate building and publishing of your package.
Go to: Pipelines for building
Q: How do I migrate from Anaconda to venv or Micromamba?
There are easy alternatives, just use micromamba!
Go to: Migrate away from Anaconda
Q: How to convert a micromamba/mamba/conda environment into a container?
Why? You can convert you existing environment into just one file and run it even more efficient than having a hundreds of small files. Build your environment and take it with you. Every Server, HPC or Laptop can have apptainer installed and execute your kernel.
This can be an excellent way to deploy a conda environment on VSC.
Convert a conda environment into a container
Bash | |
---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
|