[Solved] Load module when calling python in macro

Java, C++, C#, Delphi... - Using the UNO bridges
Locked
luofeiyu
Posts: 53
Joined: Thu Sep 14, 2017 2:11 am

[Solved] Load module when calling python in macro

Post by luofeiyu »

In my python console:

Code: Select all

import os
print(os.__file__)
/usr/lib/python3.11/os.py
import lxml
print(lxml.__file__)
/usr/lib/python3/dist-packages/lxml/__init__.py
Write python function for macro to call.

Code: Select all

cd  .config/libreoffice/4/user/Scripts/python
vim  hello.py
import uno
def HelloWorldPythonCalc():
    import os
    import lxml
    return None
It encounter error:
call.png
call.png (53.85 KiB) Viewed 8900 times
Why can't import the module "lxml" in basic macro?Does it means that openoffice basic macro can only support part of python libraries ?So,can't fix it?
Last edited by robleyd on Tue Feb 04, 2025 2:25 am, edited 2 times in total.
Reason: Add green tick
LibreOffice 7.4.7.2 on Debian 12
User avatar
karolus
Volunteer
Posts: 1226
Joined: Sat Jul 02, 2011 9:47 am

Re: Load module when calling python in macro

Post by karolus »

Work with the Libreoffice mentioned in your signature: LibreOffice 7.4.7.2 on Debian 12
AOO4, Libreoffice 6.1 on Rasbian OS (on ARM)
Libreoffice 7.4 on Debian 12 (Bookworm) (on RaspberryPI4)
Libreoffice 24.8… flatpak on Debian 12 (Bookworm) (on RaspberryPI4)
luofeiyu
Posts: 53
Joined: Thu Sep 14, 2017 2:11 am

Re: Load module when calling python in macro

Post by luofeiyu »

Install package into /opt/libreoffice24.8/program with argument target:

Code: Select all

sudo python3 -m pip install  lxml  --target=/opt/libreoffice24.8/program
LibreOffice 7.4.7.2 on Debian 12
Locked