Bug 159988 - LibreOffice 24.2.x can't import python binary
Summary: LibreOffice 24.2.x can't import python binary
Status: VERIFIED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Extensions (show other bugs)
Version:
(earliest affected)
24.2.1.2 release
Hardware: All Linux (All)
: medium normal
Assignee: Xisco Faulí
URL:
Whiteboard: target:25.8.0 target:25.2.1
Keywords:
Depends on:
Blocks: Macro-Python
  Show dependency treegraph
 
Reported: 2024-03-01 18:19 UTC by prrvchr
Modified: 2025-02-06 09:24 UTC (History)
7 users (show)

See Also:
Crash report or crash signature:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description prrvchr 2024-03-01 18:19:09 UTC
Description:
I use Python packages providing binary files in my extensions:
- cffi
- ijson
- lxml

To package these 3 python libraries in the extension I just need to put a copy of the library in the pythonpath folder of the extension with all the binary files for all the different architectures.

It worked perfectly with LibreOffice 5.x, 6.x and 7.x on Windows and Linux, it works with LibreOffice 24.2.1.2 on Windows 10.

With LibreOffice 24.2.x under Linux this no longer seems possible.

Steps to Reproduce:
1.Try to install the OAuth2OOo extension [1] with 24.2.x on Linux
2.During installation an error occurs when importing the lxml module
3.Installation is interrupted

Actual Results:
Unable to install python packages with binaries under LibreOffice 24.2.x on Linux

Expected Results:
Be able to install python packages with binaries under LibreOffice 24.2.x on Linux



Reproducible: Always


User Profile Reset: No

Additional Info:
[1] https://prrvchr.github.io/OAuth2OOo/
Comment 1 prrvchr 2024-03-04 12:11:57 UTC
How to reproduce without using the OAuth2OOo extension:

The case where it works:
- Install LibreOffice 24.2.x on Windows 10 64bits. 
- download and decompress the lxml package[1] for Windows amd64 / Python 3.8 into a directory.
- Place the contents (ie: lxml-5.1.0.dist-info and lxml directory) of this archive in the LibreOffice Python lib directory (ie: C:\Program Files\LibreOffice\program\python-core-3.8.18\lib)
- Open a terminal and place this in the folder: C:\Program Files\LibreOffice\program.
- Load the Python console with the command: .\python
- In the Python console import the lxml and etree modules using the commands:
  - import lxml
  - from lxml import etree
- The 2 modules will be loaded correctly.

The case where it doesn't work:
- Install LibreOffice 24.2.x on Linux x86_64. 
- download and decompress the lxml package[2] for Linux x86_64 / Python 3.8 into a directory.
- Place the contents (ie: lxml-5.1.0.dist-info and lxml directory) of this archive in the LibreOffice Python lib directory (ie: /opt/libreoffice24.2/program/python-core-3.8.18/lib)
- Open a terminal and place this in the folder: /opt/libreoffice24.2/program.
- Load the Python console with the command: ./python
- In the Python console import the lxml and etree modules using the commands:
  - import lxml
  - from lxml import etree
- When you import etree you will get the error: ImportError: cannot import name 'etree' from 'lxml' (/opt/libreoffice24.2/program/python-core-3.8.18/lib/lxml/__init__.py)


[1] https://files.pythonhosted.org/packages/86/65/3d582b968b9b6c3efdc4e54f36878d0b79c51af10ec7c9d02d08dd72314b/lxml-5.1.0-cp38-cp38-win_amd64.whl

[2] https://files.pythonhosted.org/packages/ee/08/8cb09c9a0d77e7b615ace332a76e6460f4c3b0a50654c181755c619c383e/lxml-5.1.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Comment 2 prrvchr 2024-03-04 12:16:47 UTC
Last clarification: this is not necessarily linked to the python lxml package but to the fact that they have binary files since I have the same problem with the ijson, cffi and charser-normalizer packages.
Comment 3 prrvchr 2024-03-08 00:45:33 UTC
I think this additional information will be enough to resolve this problem.

- In LibreOffice 24.2.x python console for Windows 10, I get:
>>> import distutils.sysconfig as ds
>>> print(ds.get_config_var("EXT_SUFFIX"))
.cp38-win_amd64.pyd

- In LibreOffice 24.2.x python console for Linux, I get:
>>> import distutils.sysconfig as ds
>>> print(ds.get_config_var("EXT_SUFFIX"))
.cpython-3.8.so

It turns out that EXT_SUFFIX does not have the correct value which should be:
.cpython-38-x86_64-linux-gnu.so

Besides, if I rename the binary files under the wrong name I can import them...
Comment 4 prrvchr 2024-03-10 10:40:20 UTC
I do not have the possibility to test under MacOS what about LibreOffice version 24.2. x under OSX?
Comment 5 Roman Kuznetsov 2024-09-09 16:33:37 UTC
cloph, could you please take a look?
Comment 6 Xisco Faulí 2025-01-20 13:27:20 UTC
Hi Pierre,
Looking at the links you mentioned in 1, https://files.pythonhosted.org/packages/ee/08/8cb09c9a0d77e7b615ace332a76e6460f4c3b0a50654c181755c619c383e/lxml-5.1.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl wouldn't work even if EXT_SUFFIX were '.cpython-38-x86_64-linux-gnu' because the suffix of this file is '.manylinux2014_x86_64'.
Are you sure it worked with LibreOffice prior to 7.6 ?
Comment 7 prrvchr 2025-01-20 17:40:06 UTC
Hi Xisco,

If you look in the file:
https://files.pythonhosted.org/packages/ee/08/8cb09c9a0d77e7b615ace332a76e6460f4c3b0a50654c181755c619c383e/lxml-5.1.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

you will find:
- lxml/_elementpath.cpython-38-x86_64-linux-gnu.so
- lxml/builder.cpython-38-x86_64-linux-gnu.so
- lxml/etree.cpython-38-x86_64-linux-gnu.so
- lxml/objectify.cpython-38-x86_64-linux-gnu.so
- lxml/sax.cpython-38-x86_64-linux-gnu.so
- lxml/html/clean.cpython-38-x86_64-linux-gnu.so
- lxml/html/diff.cpython-38-x86_64-linux-gnu.so

all these files end with: .cpython-38-x86_64-linux-gnu.so
Comment 8 prrvchr 2025-01-20 18:30:23 UTC
@Xisco

> Are you sure it worked with LibreOffice prior to 7.6?

Actually, I have never tested it and I fear it has never worked.

So far, on Linux, I have only used LibreOffice publishing via Ubuntu packages and that does not package Python with LibreOffice.
Comment 9 Xisco Faulí 2025-01-27 11:06:26 UTC
Hi Pierre,
Sorry for my previous comment, I was talking nonsense.
The issue described here is the same as when installing numpy through pip, see https://bugs.documentfoundation.org/show_bug.cgi?id=143980#c15. For now, a workaround is to run

for file in $(find instdir/program -name *.cpython-311-x86_64-linux-gnu.so); do cp "${file}" "${file/.cpython-311-x86_64-linux-gnu.so/.cpython-3.11.so}"; done
Comment 10 Xisco Faulí 2025-01-27 11:30:17 UTC
oh, interesting, LibreOffice compilation removes the suffix in external/python3/python-3.5.tweak.strip.soabi.patch
Comment 11 Commit Notification 2025-01-27 14:47:05 UTC
Xisco Fauli committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/3575986e30705d588d4eea94eb669474a3adbf77

tdf#162786, tdf#159988: python3: do not strip soabi on linux/macOS

It will be available in 25.8.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 12 prrvchr 2025-01-28 14:13:54 UTC
Hi Cisco,

> for file in $(find instdir/program -name *.cpython-311-x86_64-linux-gnu.so); do cp "${file}" "${file/.cpython-311-x86_64-linux-gnu.so/.cpython-3.11.so}"; done

Since I noticed this issue, as a workaround, I make a link with the wrong file name (ie: *.cpython-3.8 and *.cpython-3.9).

Did you manage to fix this problem and make EXT_SUFFIX return .cpython-38-x86_64-linux-gnu.so?
The same problem, if it exists on the Apple Mac platforms, has it been resolved?

I think that if we can answer these two questions then I will be able to close...
Comment 13 Xisco Faulí 2025-01-28 14:47:52 UTC
(In reply to prrvchr from comment #12)
> Hi Cisco,
> 
> > for file in $(find instdir/program -name *.cpython-311-x86_64-linux-gnu.so); do cp "${file}" "${file/.cpython-311-x86_64-linux-gnu.so/.cpython-3.11.so}"; done
> 
> Since I noticed this issue, as a workaround, I make a link with the wrong
> file name (ie: *.cpython-3.8 and *.cpython-3.9).
> 
> Did you manage to fix this problem and make EXT_SUFFIX return
> .cpython-38-x86_64-linux-gnu.so?
> The same problem, if it exists on the Apple Mac platforms, has it been
> resolved?
> 
> I think that if we can answer these two questions then I will be able to
> close...

Hi Pierre,
See comment 11. Yesterday I submitted a patch to master with the fix. it should be already available in daily builds and it should fix the problem on Linux and on Mac
Comment 14 prrvchr 2025-01-28 16:56:41 UTC
@Xisco

Ok, I will do the tests on the daily build and if someone can confirm that EXT_SUFFIX is correct on Apple Mac platform (I can't test) then I close.

Thanks for this fix.
Comment 15 jeanmarczambon 2025-02-01 13:00:10 UTC
Hi,

I made quick tests on

Version: 25.8.0.0.alpha0+ (X86_64) / LibreOffice Community
Build ID: b0a4afc58e1c9434e56ddb96c41f4ebe5985ed0a
CPU threads: 4; OS: Linux 6.8; UI render: default; VCL: gtk3
Locale: fr-BE (fr_BE.UTF-8); UI: en-US
Calc: threaded

with the Apso package manager (https://gitlab.com/jmzambon/apso#package-manager-beta-feature), after disabling the current workaround.

Everything seems to work fine.

So thank you Xisco!
Comment 16 BogdanB 2025-02-01 14:48:52 UTC
Verified based on comment 15.
Comment 17 Commit Notification 2025-02-06 09:24:27 UTC
Xisco Fauli committed a patch related to this issue.
It has been pushed to "libreoffice-25-2":

https://git.libreoffice.org/core/commit/e0c736642a34d10d899fc8a8a55ef2483b6b46d5

tdf#162786, tdf#159988: python3: do not strip soabi on linux/macOS

It will be available in 25.2.1.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.