Bug 116412 - Bundled python fails to import bz2 on Windows
Summary: Bundled python fails to import bz2 on Windows
Status: NEW
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: LibreOffice (show other bugs)
Version:
(earliest affected)
6.0.2.1 release
Hardware: x86-64 (AMD64) Windows (All)
: medium normal
Assignee: Not Assigned
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: Macro-Python
  Show dependency treegraph
 
Reported: 2018-03-15 02:36 UTC by Takeshi Abe
Modified: 2020-11-19 11:03 UTC (History)
3 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 Takeshi Abe 2018-03-15 02:36:07 UTC
Description:
Importing bz2 module of Python fails with the following error message:
ImportError: No module named '__bz2'

Steps to Reproduce:
1. Start Command Prompt
2. > cd "C:\Program Files\LibreOffice\program"
3. > python
4. >>> import bz2

Actual Results:  
Got an ImportError:
---
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Program Files\LibreOffice\program\python-core-3.5.4\lib\bz2.py", line 22, in <module>
    from _bz2 import BZ2Compressor, BZ2Decompressor
ImportError: No module named '_bz2'
>>>
---

Expected Results:
Module bz2 is imported successfully.


Reproducible: Always


User Profile Reset: No



Additional Info:
Version: 6.0.2.1 (x64)
Build ID: f7f06a8f319e4b62f9bc5095aa112a65d2f3ac89
CPU threads: 8; OS: Windows 10.0; UI render: default; 
Locale: en-US (en_US); Calc: group

On the other hand, importing bz2 succeeds with python of macOS version of LibO 6.0.2.


User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Firefox/52.0
Comment 1 Buovjaga 2018-03-16 14:07:57 UTC
Repro.

Version: 6.0.2.1 (x64)
Build ID: f7f06a8f319e4b62f9bc5095aa112a65d2f3ac89
CPU threads: 4; OS: Windows 10.0; UI render: default; 
Locale: fi-FI (fi_FI); Calc: group
Comment 2 QA Administrators 2019-03-17 03:51:38 UTC Comment hidden (obsolete)
Comment 3 Takeshi Abe 2019-03-18 00:57:23 UTC
Still reproducible with:

Version: 6.2.1.2 (x64)
Build ID: 7bcb35dc3024a62dea0caee87020152d1ee96e71
CPU threads: 8; OS: Windows 10.0; UI render: default; VCL: win; 
Locale: en-US (en_US); UI-Language: en-US
Calc: threaded
Comment 4 Kim 2020-06-30 09:44:29 UTC
This problem persists. 
when importing bz2...


Python 3.7.7 (default, Jun 24 2020, 22:27:58) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import bz2
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Program Files\LibreOffice\program\python-core-3.7.7\lib\bz2.py", line 19, in <module>
    from _bz2 import BZ2Compressor, BZ2Decompressor
ModuleNotFoundError: No module named '_bz2'


Found this when trying to use Pandas


problem is unique to the version of python included with LibreOffice.



Additional info
Version: 6.4.5.2 (x64)
Build ID: a726b36747cf2001e06b58ad5db1aa3a9a1872d6
CPU threads: 12; OS: Windows 10.0 Build 18363; UI render: default; VCL: win; 
Locale: en-GB (en_GB); UI-Language: en-GB
Calc: CL
Comment 5 elmau 2020-07-11 14:49:41 UTC
Python 3.7.7 (default, Jul  3 2020, 17:23:00) [MSC v.1925 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import bz2
>>>

1) Install Python 3.7.7
2) Copy from: C:\Program Files\Python37\DLLs\_bz2.pyd
3) Paste in: C:\Program Files\LibreOffice\program\python-core-3.7.7\lib

But... I don't understand why many libraries of Python are trimmed in LibreOffice for Windows, like sqlite3 for example :(
Comment 6 elmau 2020-09-16 19:43:16 UTC
Still reproducible with:

ArchLinux
LibreOffice appImage
Version: 7.0.1.2
Build ID: 7cbcfc562f6eb6708b5ff7d7397325de9e764452
CPU threads: 8; OS: Linux 5.8; UI render: default; VCL: gtk3
Locale: en-US (en_US.UTF-8); UI: en-US
Calc: threaded

Python 3.7.7 (default, Aug 27 2020, 22:20:34) 
[GCC 7.3.1 20180303 (Red Hat 7.3.1-5)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import bz2
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/tmp/.mount_LibreOMUTeE3/opt/libreoffice7.0/program/python-core-3.7.7/lib/bz2.py", line 19, in <module>
    from _bz2 import BZ2Compressor, BZ2Decompressor
ModuleNotFoundError: No module named '_bz2'
>>>
Comment 7 Thomas Viehmann 2020-11-19 09:35:12 UTC
I think I found the reason here, at least for the Linux side:
The libreoffice bundled Python doesn't include an "arch triple" when looking for binary (.so), i.e. for the typical wheel, you'll have foo.cpython-37m-x86_64-linux-gnu.so but libreoffice only looks for foo.cpython-3.7m.so.

I'll look at making a patch.
Comment 8 Thomas Viehmann 2020-11-19 11:03:29 UTC
This isn't the bug I met, so I'll take it back.
The root cause here is that LibreOffice drops C extension modules from the standard library. One remedy could be to put them into whatever extension needs them (but it's a mess).

There is another aspect that external modules are not as easy, but this isn't the core of this bug report, I guess, so I'll not hijack it.