Install Python Package for Libre Office

How is a python package for the Libre Office Version installed? pip installed it to my system version of python (V3.9.0) which LO doesn’t access. (Common problem without a real answer.)

Win10

APSO python console [LibreOffice]
3.7.10 (default, May  6 2021, 16:23:28) [MSC v.1928 64 bit (AMD64)]
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os
<module 'os' from 'C:\\Program Files\\LibreOffice\\program\\python-core-3.7.10\\lib\\os.py'>

Related: numpy in LibreOffice Calc Installing packages (e.g. Numpy) to LO python interpreter on MacOS How do I install pip in Libreoffice's embedded Python on Linux? Macro Python

As I’ve said in your bug report, using get-pip.py (make sure to use LO’s bundled python.exe to run it) for versions 7.1/7.2 should work.

1 Like

Install as follows:

  1. Download the https://bootstrap.pypa.io/get-pip.py file
  2. Start a command prompt, preferably with administrator permissions
  3. Change to the LibreOfice installation directory (eg cd C:\Program Files\LibreOffice\program)
  4. Run python get-pip.py
  5. Close command prompt

To install my-package change to the LibreOffice installation directory and run:

C:\Program Files\LibreOffice\program>python -m pip install my-package

More details at: How update Libre Office Python on windows? - Stack Overflow

Unfortunetly I have no expertise for Windows … so try with:

pip install numpy --user --upgrade

with the optional --user its installed to your user-sitepackage-folder … theris also access from LO-python.
I prefer --user anyway because no admin-priveleges need.
In case something doesent work, visit docs for site

No luck with --upgrade.

C:\Users\User>pip install --prefix="C:\Program Files\LibreOffice\program\python-core-3.7.10\lib\site-packages" scipy.optimize
ERROR: Could not find a version that satisfies the requirement scipy.optimize (from versions: none)
ERROR: No matching distribution found for scipy.optimize

I understand this is a mismatch of python versions (System is 3.9 and LO is 3.7). LO has no pip installed. What is the way forward?

and without --upgrade ?

C:\Program Files\LibreOffice\program\python-core-3.7.10\lib\site-packages>pip install --user scipy.optimize
ERROR: Could not find a version that satisfies the requirement scipy.optimize (from versions: none)
ERROR: No matching distribution found for scipy.optimize

C:\Program Files\LibreOffice\program\python-core-3.7.10\lib\site-packages>pip install --user --upgrade scipy.optimize
ERROR: Could not find a version that satisfies the requirement scipy.optimize (from versions: none)
ERROR: No matching distribution found for scipy.optimize

Seem it is broken - pip 21 under LibreOffice for Windows - Import Error · Issue #10006 · pypa/pip · GitHub and https://bugs.documentfoundation.org/show_bug.cgi?id=143867

.
Best workaround might be to install same python version in a venv and, as suggested by others, copy site-packages folder over.

.
Why can’t LO python be just loaded in a venv?

I’ve asked the same question some time ago (German forum) and in my simple case just copied the modules myself in the directory I found out by checking PYTHONPATH from the shell I’ve started via APSO.
Works for others too as shown here for beautifulsoup: Forum openoffice.org

I asserted my installed Python has the same version, than the Python in my LibreOffice to avoid problems.

However I found this text on installing via pip to modified destinations transang.me Python custom location so I’m not sure if there is a solution for all cases.

If need arises I’ll try the pip in my external python with -target first, giving the dir of the Python in LibreOffice as destination.
For more complex situations pip may fail providing a working install. It seems there are a lot of options I never used with pip…
xkcd

Edit: some typos…

iirc copying files breaks pip functionality. It’s unreasonable to expect the same version of python will be running on system and LO.
.
os.environ['PYTHONPATH'] - PYTHONPATH is used in LO install but it is optional for a python install and I don’t use it for my system python.

The definite solution for that kind of issue is:
work with any of the mainstream Linux-distributions, they come with Libreoffice linked to python from Distribution.

So you can install packages in LO v7.2?

No, because I’m working on a tiny…:

  • Hardware Raspberry 4 B with 8Gb of RAM (armhf-platform)

  • OS: Raspberry Pi Os ( a Debian-distro compiled for armhf ), Python 3.7.2 , Libreoffice Version: 6.1.5.2
    Build-ID: 1:6.1.5-3+rpi1+deb10u7+rpt1

and it works with a heavy load of third-party Pythonpackages like Numpy, pandas, ‘jupyter notebook’, etc.

Obviously it is not straightforward to add packages to the build in python. The question is recurring. Can the constraint also be related to issues like stability, the prediction of certainty that the LO programs work well in all the corners of its application. Either in LO original downloads or LO versions included through Linux distribution managers.

I use this ZazPip extension to install python packages in libreoffice via pip:
https://git.cuates.net/elmau/zaz-pip/raw/branch/master/files/ZAZPip_v0.8.0.oxt

It was developed by @elmau (Mauricio Baeza), has an explanatory video in Spanish, but it is very intuitive to understand:

Thanks all, what a *&^% process.

.
Installed Zaz-Pip, watched video to understand to run it with Shift-Ctrl-Alt-P, downloaded pip with warnings not in path.

.
It would not install package so I changed into pip.exe directory and ran pip install --user scipy which returned error python38.dll not found.

.
Copied dll into directory then ran command again, tested sucessfully with C:\Program Files\LibreOffice\program\python.exe


C:\Users\User\AppData\Roaming\Python\Python38\Scripts>pip install --user scipy
Collecting scipy
  Downloading scipy-1.7.1-cp38-cp38-win_amd64.whl (33.7 MB)
     |████████████████████████████████| 33.7 MB 16 kB/s
Collecting numpy<1.23.0,>=1.16.5
  Downloading numpy-1.21.1-cp38-cp38-win_amd64.whl (14.0 MB)
     |████████████████████████████████| 14.0 MB 104 kB/s
Installing collected packages: numpy, scipy
  WARNING: The script f2py.exe is installed in 'C:\Users\User\AppData\Roaming\Python\Python38\Scripts' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed numpy-1.21.1 scipy-1.7.1

I made a demonstration video of the Zaz-pip extension, I used a Windows 10 VM with libreoffice portable.

https://streamable.com/n1rc9d


First you need to install the extension ZAZPip_v0.8.0.oxt

Open the extension in Libreoffice Tools > Add-Ons > Open Pip

button “Install Pip”

then enter “Admin Pip”

And install the desired packages.

In the example I typed the name of a non-existent package and clicked the install button - it displays an error message.

Then I typed in the correct package name (py3o.template) and clicked the install button


Now in your APSO python macro just use:
import py3o.template


In the example I used this pip package:

But you can reproduce this same action and install any other python packages

2 Likes

It will return an error python38.dll not found unless it is in the current folder or path.