Page 1 of 1

[Solved] Add Module in LibreOffice

PostPosted: Tue Mar 09, 2021 7:49 pm
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

Re: Add Module in LibreOffice

PostPosted: Wed Mar 10, 2021 3:55 pm
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

Re: Add Module in LibreOffice

PostPosted: Fri Mar 12, 2021 1:56 am
by Mountaineer
You may check what pythonpath your LibreOffice has set.

Code: Select all   Expand viewCollapse view
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...)

Re: Add Module in LibreOffice

PostPosted: Sat Mar 13, 2021 8:14 am
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.

Re: Add Module in LibreOffice

PostPosted: Wed Mar 17, 2021 7:11 pm
by El Catala
Good evening,

Travel income, I read your message.
The command:
Code: Select all   Expand viewCollapse view
import os
print (os.environ['PYTHONPATH'])

returns:
Code: Select all   Expand viewCollapse view
/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   Expand viewCollapse view
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   Expand viewCollapse view
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

Re: Add Module in LibreOffice

PostPosted: Thu Mar 18, 2021 12:54 am
by Villeroy
I think it is a question for a Python forum.

Re: Add Module in LibreOffice

PostPosted: Sun Mar 21, 2021 10:01 am
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   Expand viewCollapse view
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

Re: [Solved] Add Module in LibreOffice

PostPosted: Sun Mar 21, 2021 12:00 pm
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?

Re: [Solved] Add Module in LibreOffice

PostPosted: Sun Mar 21, 2021 4:05 pm
by El Catala
Hello,

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

Good night