Hi Hari,
your seconds suggestion did the trick. I had installed a pre-built version of python3.9 before, that had appearently not been compiled with the --enable-shared option.
I followed this manual: https://linuxize.com/post/how-to-install-python-3-9-on-ubuntu-20-04/ to compile my own python3.9 and set the configure option --enable-shared. Then I deleted the temporary matlab files in the package directory, and now it works.
Thank you.