[Solved] Add Module in LibreOffice

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
El Catala
Posts: 22
Joined: Mon Dec 07, 2020 6:29 pm

[Solved] Add Module in LibreOffice

Post by El Catala »

Good evening,

In python, I made a script which uses the beautifulsoup4 and requests modules.

These two modules are not present in libreoffice.
All my research on the internet did not come up with anything.

It's a shame because the script works fine when I run it from a python editor.
On the other hand, I will have wished

launch it from an LO Base form, especially since I import the result of the script into a table.

Is there a solution to add them to libreoffice?

Thank you in advance for your replies.

cordially
Last edited by El Catala on Sun Mar 21, 2021 10:02 am, edited 1 time in total.
LibreOffice 7.0.4 Xubuntu 20.4
User avatar
Villeroy
Volunteer
Posts: 31269
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Add Module in LibreOffice

Post by Villeroy »

The LibreOffice your distro should use the same Python runtime with the same libs as the rest of your system. I would expect that this is not the case with flatpak or similar packages. Certainly, it is not the case with manually downloaded office suites. My LO 6.0 which was installed with Ubuntu 18.4. can import all the modules that are accessible through the system's python3 runtime. The other office suites come with their own python runtime because the office python needs to be compiled with the same compiler as the office itself. Somehow it might be possible to add libraries to these pythons.

P.S: https://help.libreoffice.org/latest/en- ... mport.html
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Mountaineer
Posts: 310
Joined: Sun Sep 06, 2020 8:27 am

Re: Add Module in LibreOffice

Post by Mountaineer »

You may check what pythonpath your LibreOffice has set.

Code: Select all

import os
print(os.environ['PYTHONPATH'])
entered in the python-shell shows you wher th LO-Version searches for Modules.
You may then place beautifulsoup there.

I've read PIP is not recommended for embedded python ,
but you may try -target as an option.

J.

EDIT: Typos corrected (as I used my mobile phone...)
Last edited by Mountaineer on Sat Mar 13, 2021 10:58 am, edited 1 time in total.
OpenOffice 3.1 on Windows Vista
El Catala
Posts: 22
Joined: Mon Dec 07, 2020 6:29 pm

Re: Add Module in LibreOffice

Post by El Catala »

Hello, thank you for your answers.
Traveling until Thursday March 18, I can not be able to solve this problem before.
As soon as I get back, I look at this and will give you the result of your solutions.

Good day to all.
LibreOffice 7.0.4 Xubuntu 20.4
El Catala
Posts: 22
Joined: Mon Dec 07, 2020 6:29 pm

Re: Add Module in LibreOffice

Post by El Catala »

Good evening,

Travel income, I read your message.
The command:

Code: Select all

import os
print (os.environ['PYTHONPATH'])
returns:

Code: Select all

/opt/libreoffice7.0/program/../program/python-core-3.7.7/lib:/opt/libreoffice7.0/program/../program/python-core-3.7.7/lib/lib-dynload:/opt/libreoffice7.0/program/../program/python-core-3.7.7/lib/lib-tk:/opt/libreoffice7.0/program/../program/python-core-3.7.7/lib/site-packages:/opt/libreoffice7.0/program/../program
On the other hand, the end of your text leaves me perplexed.
Actually, I don't know how to set the command to install the modules for example:

Code: Select all

sudo pip3 install requests /opt/libreoffice7.0/program/python-core-3.7.7/lib/site-packages/
I get the following error message:

Code: Select all

ERROR: Directory '/opt/libreoffice7.0/program/python-core-3.7.7/lib/site-packages/' is not installable. Neither 'setup.py' nor 'pyproject.toml' found.
Could you tell me more?

cordially
Cordially
LibreOffice 7.0.4 Xubuntu 20.4
User avatar
Villeroy
Volunteer
Posts: 31269
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Add Module in LibreOffice

Post by Villeroy »

I think it is a question for a Python forum.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
El Catala
Posts: 22
Joined: Mon Dec 07, 2020 6:29 pm

Re: Add Module in LibreOffice

Post by El Catala »

Hello,


Eureka, I found it. 
Thanks to the command below, I was able to install the files necessary for the proper functioning of beautifulsoup4.

Code: Select all

sudo cp -r /usr/lib/libreoffice/program/soupsieve-2.0.1.dist-info /opt/libreoffice7.0/program/python-core-3.7.7/lib
Thank you for your support which allowed me to solve this problem.
Cordially
LibreOffice 7.0.4 Xubuntu 20.4
User avatar
Villeroy
Volunteer
Posts: 31269
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: [Solved] Add Module in LibreOffice

Post by Villeroy »

Thank you very much for sharing your knowledge. Is soupsieve-2.0.1.dist-info a file or a directory? Would a symlink work as well?
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
El Catala
Posts: 22
Joined: Mon Dec 07, 2020 6:29 pm

Re: [Solved] Add Module in LibreOffice

Post by El Catala »

Hello,

I also copied the two soupsiève directories.
Sorry, I should have made that clear.

Good night
LibreOffice 7.0.4 Xubuntu 20.4
Post Reply