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 |
|
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.
Conda environment | |
---|---|
1 2 3 4 5 6 |
|
micromamba environment | |
---|---|
1 2 3 4 5 |
|
Q: Installing Cartopy on Jet Cluster or any other module based environment?
The user needs to load geos
and proj
libraries and install via
pip install --user cartopy
or create an anaconda environment and install there.
Installing from conda-forge
is also possible, without loading any modules.
e.g. conda install -c conda-forge cartopy
in a conda environment.
This installs the libraries as well. (Not recommended)
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
Q: How to create a user environment?
The idea is to install a conda or virtual environment and use that as a kernel for your notebooks. Please note the solution for cartopy
Q: The Notebook server on the TeachingHub won't start?
This usually happens because of an old configuration. Try to remove ~/.jupyter
on SRVX1.
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.
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 add a new package to anaconda module?
It is relativly easy to install additional packages to a anaconda module distribution with pip install --user
.
Q: How to restore a conda environment?
Save/Restore conda environment
Ever needed to backup a conda environment or copy from a colleague or designing one by hand to give to others?
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.
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.
Q: How to read BUFR files with python?
ECMWF created a python package that helps to read BUFR messages via ECCODES into pandas DataFrame.
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.
Q: How to retrieve data from MARS in python?
ECMWF has created a package that allows to retrieve data from MARS, easily.
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.
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 |
|
Created: January 26, 2023