Build LibreOffice Uno libraries for python3

I want to use uno libraries to disable some of the menu options in Libreoffice document.

  1. Os Using: Linux

uname -a
Linux Tue Feb 4 23:02:59 UTC 2020 x86_64 x86_64 x
86_64 GNU/Linux Red Hat 4.8.5-39

  1. Python version : Python 3.6.8
  2. libreoffice version - LibreOffice 5.3.6.130(Build:1)

I am not able to do “import uno” or “import pyuno” in python 3. However both commands are working properly in Python2

Error I am getting in python 3:

>>> import pyuno
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: dynamic module does not define module export function (PyInit_pyuno)
>>> import uno
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'uno'

Some of the more research which I have done

(/usr/lib64/libreoffice/program)-1037> objdump -t -T -r -R pyuno.so | grep initpyuno
0000000000000a90 g    DF .text  0000000000000117  Base        initpyuno

I think my libreoffice is built against Python 2.x . But I wasnt able to find any solution how to build it against python3.x

I have posted the same iisue in stackoverflow “python - Build LibreOffice Uno libraries for python3 - Stack Overflow

Thanks in advance.

Also cross posted to AOO forum

Hi

Please check that LibreOffice Python scripting framework is present following these instructions:
https://help.libreoffice.org/latest/en-US/text/sbasic/python/main0000.html

if so, please provide the output of the following Python shell commands:

>>> import sys
>>> sys.path

Yeah it have

(/usr/lib64/libreoffice/share/Scripts/python)-997> ls

Capitalise.py Capitalise.pyo HelloWorld.pyc pythonSamples
Capitalise.pyc HelloWorld.py HelloWorld.pyo

As asked python shell commands

For python 2:

(/usr/lib64/libreoffice/share/Scripts/python)-999> python2
Python 2.7.5 (default, Aug 7 2019, 00:51:29)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux2
Type “help”, “copyright”, “credits” or “license” for more information.

import sys

sys.path

[’’, ‘/usr/lib64/python27.zip’, ‘/usr/lib64/python2.7’, ‘/usr/lib64/python2.7/plat-linux2’, ‘/usr/lib64/python2.7/lib-tk’, ‘/usr/lib64/python2.7/lib-old’, ‘/usr/lib64/python2.7/lib-dynload’, ‘/home/z003h62v/.local/lib/python2.7/site-packages’, ‘/usr/lib64/python2.7/site-packages’, ‘/usr/lib64/python2.7/site-packages/gtk-2.0’, ‘/usr/lib/python2.7/site-packages’]

import uno

For python 3: please see in next comment( length constraint)

(/usr/lib64/libreoffice/share/Scripts/python)-1000> python3

Python 3.6.8 (default, Aug 7 2019, 17:28:10)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux
Type “help”, “copyright”, “credits” or “license” for more information.

import sys

sys.path

[’’, ‘/usr/lib64/python36.zip’, ‘/usr/lib64/python3.6’, ‘/usr/lib64/python3.6/lib-dynload’, ‘/home/z003h62v/.local/lib/python3.6/site-packages’, ‘/usr/lib64/python3.6/site-packages’, ‘/usr/lib/python3.6/site-packages’]

import uno

Traceback (most recent call last):

File “”, line 1, in

ModuleNotFoundError: No module named ‘uno’

Thx

I guess you have a 3rd Python copy inside LibreOffice …

I don’t hold a RedHat distribution, however LibreOffice generally embeds its own Python interpreter, that includes the uno module. It should be located in /program directory.

More info in https://wiki.documentfoundation.org/Macros/Python_Design_Guide#Developing
Python Interactive Shell

Yeah it has some files in :

(/usr/lib64/libreoffice/program)-998> ls *python*
libpythonloaderlo.so  pythonloader.py  pythonloader.pyc  pythonloader.pyo  pythonloader.unorc  pythonscript.py  pythonscript.pyc  pythonscript.pyo

So what should I do to import uno in pycharm for python3 . I am able to do for python2?