Fixes #26531. Copies the matplotlib solution, as mentioned by @knedlsepp.
- moved expression out of python-packages - no significant changes how package is built except the supported python versions