[Solved] Add Module in LibreOffice

Creating a macro - Writing a Script - Using the API

[Solved] Add Module in LibreOffice

Postby El Catala » Tue Mar 09, 2021 7:49 pm

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
El Catala
 
Posts: 17
Joined: Mon Dec 07, 2020 6:29 pm

Re: Add Module in LibreOffice

Postby Villeroy » Wed Mar 10, 2021 3:55 pm

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
User avatar
Villeroy
Volunteer
 
Posts: 30153
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Add Module in LibreOffice

Postby Mountaineer » Fri Mar 12, 2021 1:56 am

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...)
Last edited by Mountaineer on Sat Mar 13, 2021 10:58 am, edited 1 time in total.
OpenOffice 3.1 on Windows Vista
Mountaineer
 
Posts: 93
Joined: Sun Sep 06, 2020 8:27 am

Re: Add Module in LibreOffice

Postby El Catala » Sat Mar 13, 2021 8:14 am

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: 17
Joined: Mon Dec 07, 2020 6:29 pm

Re: Add Module in LibreOffice

Postby El Catala » Wed Mar 17, 2021 7:11 pm

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
LibreOffice 7.0.4 Xubuntu 20.4
El Catala
 
Posts: 17
Joined: Mon Dec 07, 2020 6:29 pm

Re: Add Module in LibreOffice

Postby Villeroy » Thu Mar 18, 2021 12:54 am

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
User avatar
Villeroy
Volunteer
 
Posts: 30153
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Add Module in LibreOffice

Postby El Catala » Sun Mar 21, 2021 10:01 am

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
LibreOffice 7.0.4 Xubuntu 20.4
El Catala
 
Posts: 17
Joined: Mon Dec 07, 2020 6:29 pm

Re: [Solved] Add Module in LibreOffice

Postby Villeroy » Sun Mar 21, 2021 12:00 pm

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
User avatar
Villeroy
Volunteer
 
Posts: 30153
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: [Solved] Add Module in LibreOffice

Postby El Catala » Sun Mar 21, 2021 4:05 pm

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
El Catala
 
Posts: 17
Joined: Mon Dec 07, 2020 6:29 pm


Return to Macros and UNO API

Who is online

Users browsing this forum: JeJe and 6 guests