Python script error: no module named 'com'

  LibreOffice 7.5.2.2 50(Build:2)
  Linux  6.2.11-arch1-1

I can run Python macros without error but if I try to import any com.sun.. modules I get this error. Other imports from the running environment are okay.

import sys
print(sys.executable)

In case of a macro, this may be /opt/libreoffice7.5/program/soffice.bin
In a Python program, this might be /usr/lib/python3/… which knows nothing about LibreOffice.

I cannot say what the arch-package-managers do, but with me on Debian-Bullseye the executable is:

/usr/bin/soffice

and it use the python-environment provided by debian

I placed the following at the top of the script :slight_smile:

  import sys
 print(sys.executable,file=open('/home/carnish/x','w'))

The result is /usr/bin/python3

I have other python scripts that run fine. It’s only this import com… that is giving trouble.

In the case of a python macro? Should the python sys.executable be soffice.bin?

I have something wrong if that is so.

No thats wrong!
But in case you download libreoffce directly from libreoffice and install manually, the whole thing inclusive an own python-environment goes into /opt/libreoffice/program/…

A macro’s executable was reported by LO on Windows as soffice.bin. I found it plausible if the macro Python is a sub-process of the office executable.
However, on my Linux box LO7.5, the downloaded “community version” 7.5, reports /usr/bin/python3 which is not what I expected. This means that LO is shipped with an unused Python runtime.
I’m confused.

P.S. I don’t need to import uno

import sys
from com.sun.star.awt.MessageBoxType import MESSAGEBOX, INFOBOX, WARNINGBOX, ERRORBOX, QUERYBOX

def main(*a):
    s = sys.executable
    print(s)

Hallo
You probably need first

import uno

the uno-module resolves the internal import-chain into »com.sun.star…

Thank you. Here is the complete import block

 import uno
 from com.sun.star.awt import Size
 from com.sun.star.beans import PropertyValue
 from com.sun.star.drawing import LineDash, LineStyle, ShapeType
 from com.sun.star.style.LineSpacing import FIXED

I had to deal with this issue a few times.
I created OOOENV to help with this issue.
Generally it can set the uno enovironment for a given virtual environment.

I use this package in the OOO Development Tools (OooDev) project.

Because it is complex I also wrote a short guide. See OooDev Dev Docs.

BTW, for python project I have created types-unopy that gives full type support for the LibreOffice Python API.