LibreOffice on windows comes with it's own Python version. How can one install new packages for LibreOffice-Python.
I use Linux myself and I've written a working macro that I would like to be usable for windows users as well, but it uses packages that aren't available in standard LibreOffice.
We tried updating by pip, but as expected it only updates the system's python. We are aware that zazpip exists, but apparently it didn't work with the tester. Therefore I am explicitly looking for other solutions.
Quickly installing a python package with pip will most likely just make it available in python under your operating system, not LibreOffice. The python docs installing python packages describe pip usage with a warning about using python managed by another package manager (ie LibreOffice).
The python under Windows is a cut-down embedded python version (while most linux distros use their system python) without pip or get-pip.py and there are no supporting python directories in the path. LibreOffice is also installed on Windows with administrator permissions.
Install as follows:
cd C:\Program Files\LibreOffice\program
)python get-pip.py
This will install or upgrade pip for the LibreOffice version of python without affecting the operating system version. Additionally, it will install setuptools and wheel if they’re not installed already.
The installed location depends on the python installation context. For example with python v3.8.10 a WARNING will be displayed that the scripts are installed in 'C:\Program Files\LibreOffice\program\python-core-3.8.10\Scripts' for an administrator install or alternatively, 'C:\Users\User\AppData\Roaming\Python\Python38\Scripts'.
The files installed with pip and the execution is more complicated than it appears. The easiest way to use the right pip for the right python version is to run it from the python install directory using python -m
. This example is a verbose package listing:
C:\Program Files\LibreOffice\program>python -m pip list -v
Package Version Location Installer
---------- ------- ------------------------------------------------------------------------- ---------
pip 22.0.3 c:\program files\libreoffice\program\python-core-3.8.10\lib\site-packages pip
setuptools 60.9.3 c:\program files\libreoffice\program\python-core-3.8.10\lib\site-packages pip
wheel 0.37.1 c:\program files\libreoffice\program\python-core-3.8.10\lib\site-packages pip
To install my-package
change to the LibreOffice installation directory and run:
C:\Program Files\LibreOffice\program>python -m pip install my-package