Python versions mismatch with libreoffice python

Hi all

I decided to venture into developing LO macros with python instead of Basic and stumbled upon an issue wrg to a mismatch between ubuntu python version (3.12) and the LO python version (3.10) as (seen in /opt/libreoffice25.2/program/python-core-3.10.16/lib)

The way i discovered this issue was while trying to start a python console from a python script in a macro and getting this error back in journalctl

Original exception was:
Traceback (most recent call last):
File “/usr/bin/gnome-terminal”, line 3, in
import string
File “/opt/libreoffice25.2/program/python-core-3.10.16/lib/string.py”, line 52, in
import re as _re
File “/opt/libreoffice25.2/program/python-core-3.10.16/lib/re.py”, line 125, in
import sre_compile
File “/opt/libreoffice25.2/program/python-core-3.10.16/lib/sre_compile.py”, line 17, in
assert _sre.MAGIC == MAGIC, “SRE module mismatch”
^^^^^^^^^^^^^^^^^^^
Removing python3 from ubuntu for downgrading seems like an impossible mission: the only workaround I found was to replace /opt/libreoffice25.2/program/python-core-3.10.16/lib with a link to the installed python3 library directory.

Does a clean solution exists for aligning the version ?

Ubuntu 24.04.2 LTS
Linux 6.11.0-24-generic
Python 3.12.3 (main, Feb 4 2025, 14:48:35) [GCC 13.3.0] on linux
LO
Version: 25.2.2.2 (X86_64) / LibreOffice Community
Build ID: 7370d4be9e3cf6031a51beef54ff3bda878e3fac
CPU threads: 4; OS: Linux 6.11; UI render: default; VCL: gtk3
Locale: it-CH (en_US.UTF-8); UI: en-US
Calc: threaded

How is your LibreOffice installer? Snap, Flatpack, regular install?
.
IMHO regular installs should use system python, but Snap and other containers may bring their own python.

Sorry I forgot to mention, I have installed LO from DEBS downloaded from libreoffice, I avert snap and flatpaks when feasible.

I’d try the repository of ubuntu instead…

Will give it a try … i will disable snap for libreoffice.

Just had the same problem with a Windows 11 installation. I wanted a macro to start up an external python program, didn’t want to use python that came with LibreOffice. Used shell() cmd. Hardwired solution in the python program fixed the problem. In my case solution was
import sys
sys.path.insert(0, ‘C:\Program Files\Python313\Lib’)

Not ideal

Hope that saves some one some time.