Reputation: 1045
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.
Upvotes: 1
Views: 2104
Reputation: 197
I worked with the author of Zaz-Pip and fixed most all issues with installing python packages cross platform for LibreOffice.
This new version as fixed issues for Linux Flatpak and AppImge. On Mac OS now pip packages such as numpy
can be installed and will work. Previously on Mac OS installing python packages with binary *.so
files would fail when imported.
The extension can be found here.
Also I wrote Python LibreOffice Pip Extension Template if you have a need to write your own extension that needs to pip install anything. This template makes it super simple to do that.
Upvotes: 2
Reputation: 1365
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
Upvotes: 4
Reputation: 13790
A discussion of what others have tried is at https://ask.libreoffice.org/t/install-python-package-for-libre-office/66934/16. I doubt you'll find any better answers than what is described there. Try the various approaches and see what works for your situation.
I did get it to work once but it wasn't easy—some environment variables needed to be set in my case.
Is there a way to write your macro so that it does not depend on a separate package? That is what I ended up doing. You can implement part of the package yourself if needed. In the end it wasn't so bad, and it works on all operating systems.
Upvotes: 1
Reputation: 88
If it comes with a specific version of Python, it may need to reference specific functions from that version. The best answer I can give you is: If Python is included in the source code, try forking the source code with your own version of Python, and compiling that.
Or,
If there's a specific package manager for Python included, try using that to update Python.
Upvotes: 1