Bug 168215 - Embedded Python runtime lacks some important modules
Summary: Embedded Python runtime lacks some important modules
Status: UNCONFIRMED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: LibreOffice (show other bugs)
Version:
(earliest affected)
25.8.1.1 release
Hardware: x86-64 (AMD64) Windows (All)
: medium enhancement
Assignee: Not Assigned
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2025-08-31 21:46 UTC by denis.gz
Modified: 2025-09-01 04:43 UTC (History)
2 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 denis.gz 2025-08-31 21:46:28 UTC
Description:
1. No (simple) way to create virtual environment for embedded Python, using standard approach via "python.exe -m venv venv" command.
2. Missing standard modules and binaries in embedded runtime (sqlite3, _lzma.pyd and others), which makes third party modules installation/operation to fail (for example, included lzma.py won't load on Windows).
3. Missing pythonw.exe binary (note the "W" in the name!) which makes Spyder (and other GUI apps) to fail on startup. 
4. Missing import library and headers for python3.dll/python311.dll, which makes it impossible to compile some modules for which prebuilt "wheel" doesn't exist. For example, trying to replace missing sqlite3 with pysqlite3, fails due to missing Python.h (easily fixable) and missing Python3.lib (not so easily fixable).
5. Complications arose from existence of Python3.dll (shim dll, incompatible with official Python3.dll) and Python311.dll (compatible but with a non-standard name).

All these issues make developing Python scripts on Windows way more complicated than it could/should be.

Steps to Reproduce:
1. Try to run python -m venv venv
2. Try to import lzma in a script
3. Try to install something which depends on sqlite3 (for example Spyder)
4. Try to run Spyder from venv

Actual Results:
1. Fails
2. Fails
3. Fails
4. Fails

Expected Results:
1. venv is created
2. import lzma doesn't fail
3. pip install spyder doesn't fail
4. Spyder runs


Reproducible: Always


User Profile Reset: No

Additional Info:
Developing Python script on Windows is too complicated now, due to difficulties setting up (efficient in regard to time and resources) development environment. Setting up should be as simple as:
1. set PATH=C:\Program Files\LibreOffice\program;%PATH%
2. mkdir project && cd project
3. python -m venv venv
4. venv\Scripts\activate
5. pip install spyder
6. spyder

And then start developing scripts, having decent debugger and code inspection/completion.
Comment 1 denis.gz 2025-08-31 21:52:28 UTC
Workarounds exist for every step in Steps to reproduce, however they require knowledge far beyond necessary to develop Python scrips.
Comment 2 denis.gz 2025-08-31 22:55:04 UTC
Workarounds for those who interested:

1. Copy venv module from Python distribution of the same version to the
   "C:\Program Files\LibreOffice\program\python-core-3.11.13\lib" dir.
   After that, python -m venv venv command should succeed.
2. In order to install pysqlite3 with pip, you should prepare VS environment first.
   Follow these steps:
2.1 Have MSVS 2019 (any edition) installed
2.2 Download Python source code and copy contents of its Include dir to the Include dir located in the venv
2.3 Now the hard part - recreating Python3.lib:
2.3.1 Open "x64 Native Tools Command Prompt for VS 2019" console
2.3.2 Run command "dumpbin /EXPORTS Python311.dll > Python3.def"
2.3.3 Add these two lines at the beginning:
      LIBRARY PYTHON3
      EXPORTS
2.3.4 Edit/remove everything else so each line contains only a function name, like:
      PyAIter_Check
      PyArg_Parse
      PyArg_ParseTuple
      ...
      _Py_write_noraise
      
      (total 1632 functions for python311.dll)
2.3.5 Now create import library with this command:
      lib /DEF:Python3.def /OUT:Python3.lib /MACHINE:X64
2.4 Copy obtained Python3.lib to the virtual environment's venv\libs folder (don't confuse with "Lib"!)
2.5 Activate the venv and run "pip install pysqlite3", it should build the dependencies needed
2.6 Symlink or just copy pysqlite3 as sqlite3
3. If _lzma is necessary, copy _lzma.pyd from an official distribution to the "C:\Program Files\LibreOffice\program" dir.
4. Now run "pip install oooenv ooo-dev-tools types-scriptforge oooscript spyder"
5. Hope it's worked, the last step is to copy python.exe from LO program folder with the name "pythonw.exe" to the venv\Scripts folder
6. Now type "spyder" and it should run

NB: I'm writing all these from my memory so I could have missed something...
Comment 3 Ming Hua 2025-09-01 02:15:59 UTC
Removing many modules in the embedded Python is a deliberate choice made by the developers.  There is a compile-time option to use the system Python instead of the embedded one, and many Linux distributions chose this option.  Though I admit I haven't seen any Windows build doing this, and don't know how viable this approach is on Windows.

There are also extensions that installs numpy/scipy or pandas and make them work with LibreOffice.  I imagine you can also build an extension that incorporate the parts you mentioned if you choose that approach.

In any case, such a blanket report listing multiple issues is unlikely to get any traction.  The developers are not going to change their mind and embed full Python into LibO.  If you can separate this report into individual issues, some of them may get support (I'm thinking of the pythonw.exe one) and are added to the embedded Python.
Comment 4 denis.gz 2025-09-01 02:41:17 UTC
> Though I admit I haven't seen any Windows build doing this, and don't know how viable this approach is on Windows.

Although there's no "standard" Python on Windows, there are official packages published in the Windows Store from v3.8. But this is only for Win10 and later.

> There are also extensions that installs numpy/scipy or pandas and make them work with LibreOffice.  I imagine you can also build an extension that incorporate the parts you mentioned if you choose that approach.

You can't easily build anything for LO due to reasons I explained in the item #4 in Description.

> The developers are not going to change their mind and embed full Python into LibO.

There's no such thing as "lite" Python or "full" Python. It either works or is broken. The Python is LO is broken, and I explain why.