Bug 143867 - Python Implementation Poorly Conceived with No Package Installation Process
Summary: Python Implementation Poorly Conceived with No Package Installation Process
Status: RESOLVED WORKSFORME
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: LibreOffice (show other bugs)
Version:
(earliest affected)
3.3.0 release
Hardware: All Windows (All)
: medium normal
Assignee: Not Assigned
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: Macro-Python
  Show dependency treegraph
 
Reported: 2021-08-14 05:26 UTC by flywire
Modified: 2022-08-16 12:05 UTC (History)
3 users (show)

See Also:
Crash report or crash signature:


Attachments
Pip Missing DLL Error (5.98 KB, image/png)
2021-08-17 23:49 UTC, flywire
Details
Install Python pip with Python embeded LibreOffice (94.41 KB, image/png)
2021-08-21 19:41 UTC, elmau
Details

Note You need to log in before you can comment on or make changes to this bug.
Description flywire 2021-08-14 05:26:06 UTC
Python macro support is very poor. Installing packages is essential for more than trivial python use yet there is no documentation or understanding of how to do it within the LO/OO forums or python community. The installation seems poorly conceived with clashes between a python installation on the system and within LO. There is no pip to install packages within LO python. Other software using python macros has a venv to manage these issues.

Typical issue: https://ask.libreoffice.org/t/install-python-package-for-libre-office/66934/2 - crazy workarounds!
Comment 1 flywire 2021-08-14 07:16:19 UTC
https://github.com/pypa/pip/issues/10006

> The root cause is : from asyncio import sleep
Comment 2 flywire 2021-08-14 08:14:45 UTC
(In reply to flywire from comment #1)
> https://github.com/pypa/pip/issues/10006
> 
> > The root cause is : from asyncio import sleep

This is unrelated to the resolver -- the failure is happening during imports, since asyncio.sleep can't be imported. As already mentioned, asyncio is a part of the Python standard library, and if it's not importable then the Python installation is not complete, and pip isn't supported on such platforms.

----------------------------------------------------------------

The whole python implementation needs a rethink.
Comment 3 Ming Hua 2021-08-14 12:03:03 UTC
(In reply to flywire from comment #1)
> https://github.com/pypa/pip/issues/10006
> 
> > The root cause is : from asyncio import sleep

My personal experience has been that this problem only happen for LibreOffice 7.0 (with has Python 3.7 bundled), and doesn't happen for 7.1 or 7.2 (both with Python 3.8 bundled).

For me, with LibreOffice 7.1.3 RC1 on Windows 10, get-pip.py 21.1.3 installed without any problem and worked fine.

From your AskLO post you said you have Python 3.7 bundled with LO which suggests older LO version.  I suggest you upgrade to 7.1 (or 7.2, with 7.2.0 scheduled to release next week and become the new Fresh release branch) and retry the get-pip.py approach.
Comment 4 flywire 2021-08-14 12:14:05 UTC
Your comments are reassuring. I've upgrade LO and I'll try get-pip.py again.

Version: 7.2.0.3 (x64) / LibreOffice Community
Build ID: 2a7ea282da28d665a7dc086360567b4aea27bf08
CPU threads: 8; OS: Windows 10.0 Build 19043; UI render: Skia/Raster; VCL: win
Locale: en-AU (en_AU); UI: en-GB
Calc: threaded
Comment 5 elmau 2021-08-16 22:44:00 UTC
I tested install in fresh install in Windows 10 with LibO 7.2 (Py3.8) and get_pip.py work fine.
Comment 6 flywire 2021-08-17 23:49:47 UTC
Created attachment 174360 [details]
Pip Missing DLL Error

pip maintainers consider LibreOffice python install is incomplete because pip should be installed as part of the distribution - https://github.com/pypa/pip/issues/10006#issuecomment-899956947

Regardless, it will not run following pip documentation. *IF* pip is installed properly then packages install as expected.

Installing in as a venv still needs consideration.

--------------------

Tested on LibreOffice 7.2 (Python 3.8) [LibreOffice 7.0 (Python 3.7) not tested].

Following [Ensure you can run pip from the command line](https://packaging.python.org/tutorials/installing-packages/#id13)
> If that still doesn’t allow you to run python -m pip

```
Microsoft Windows [Version 10.0.19043.1165]
(c) Microsoft Corporation. All rights reserved.

C:\Program Files\LibreOffice\program>python -m get-pip.py
C:\Program Files\LibreOffice\program\python-core-3.8.10\bin\python.exe: Error while finding module specification for 'get-pip.py' (ModuleNotFoundError: __path__ attribute not found on 'get-pip' while trying to find 'get-pip.py')

C:\Program Files\LibreOffice\program>python get-pip.py
Defaulting to user installation because normal site-packages is not writeable
Collecting pip
  Using cached pip-21.2.4-py3-none-any.whl (1.6 MB)
Installing collected packages: pip
  Attempting uninstall: pip
    Found existing installation: pip 21.2.4
    Uninstalling pip-21.2.4:
      Successfully uninstalled pip-21.2.4
  WARNING: The scripts pip.exe, pip3.8.exe and pip3.exe are installed in 'C:\Users\User\AppData\Roaming\Python\Python38\Scripts' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed pip-21.2.4
```

I don't know where it found existing installation, it wasn't in the path and that folder was empty until pip was installed. Maybe `get-pip.py` needs to be downloaded to `C:\Program Files\LibreOffice\program\python-core-3.8.10\bin`.

**Sadly it won't run because the dll is not in the path or current folder:**
Comment 7 Ming Hua 2021-08-21 13:25:26 UTC
(In reply to flywire from comment #6)
> pip maintainers consider LibreOffice python install is incomplete because
> pip should be installed as part of the distribution -
> https://github.com/pypa/pip/issues/10006#issuecomment-899956947
Again, I want to point out that the problem description in that ticket seems to only apply for LO 7.0 or earlier, from my personal experience.

> Tested on LibreOffice 7.2 (Python 3.8) [LibreOffice 7.0 (Python 3.7) not
> tested].
> 
> Following [Ensure you can run pip from the command
> line](https://packaging.python.org/tutorials/installing-packages/#id13)
> > If that still doesn’t allow you to run python -m pip
> 
> ```
> Microsoft Windows [Version 10.0.19043.1165]
> (c) Microsoft Corporation. All rights reserved.
> 
> C:\Program Files\LibreOffice\program>python -m get-pip.py
> C:\Program Files\LibreOffice\program\python-core-3.8.10\bin\python.exe:
> Error while finding module specification for 'get-pip.py'
> (ModuleNotFoundError: __path__ attribute not found on 'get-pip' while trying
> to find 'get-pip.py')
Why did you do this?  get-pip.py is the filename of the script, not a python module name.  And -m requires a module parameter to follow.  This would never work, not on LO's bundled python, nor on the official python.org installation.

You should invoke the script directly with "python.exe get-pip.py", like you did below.

> C:\Program Files\LibreOffice\program>python get-pip.py
> Defaulting to user installation because normal site-packages is not writeable
Why did this happen?  Did you run the command above with an ordinary user without administrative privileges?

> Collecting pip
>   Using cached pip-21.2.4-py3-none-any.whl (1.6 MB)
> Installing collected packages: pip
>   Attempting uninstall: pip
>     Found existing installation: pip 21.2.4
>     Uninstalling pip-21.2.4:
>       Successfully uninstalled pip-21.2.4
>   WARNING: The scripts pip.exe, pip3.8.exe and pip3.exe are installed in
> 'C:\Users\User\AppData\Roaming\Python\Python38\Scripts' which is not on PATH.
>   Consider adding this directory to PATH or, if you prefer to suppress this
> warning, use --no-warn-script-location.
And here the script warned you that you are installing pip inside your home directory, which is normally not checked by LO's python.exe.

> Successfully installed pip-21.2.4
> ```
> 
> I don't know where it found existing installation, it wasn't in the path and
> that folder was empty until pip was installed. Maybe `get-pip.py` needs to
> be downloaded to `C:\Program
> Files\LibreOffice\program\python-core-3.8.10\bin`.
The get-pip.py can be placed in any folder, just make sure to run it with LO's python.  For example
  > "C:\Program Files\LibreOffice\program\python.exe" get-pip.py
can be done from any folder that contains get-pip.py.

Also make sure you run it with an admin account (or at least an account that can write to C:\Program Files\LibreOffice\), and things should go smoothly.
Comment 8 elmau 2021-08-21 19:41:47 UTC
Created attachment 174461 [details]
Install Python pip with Python embeded LibreOffice
Comment 9 elmau 2021-08-21 19:42:41 UTC
With LibO 7.2 in W10, pip install correctly again. So, we can close this issue.
Comment 10 flywire 2021-08-22 00:28:09 UTC
;TLDR Embedded LO python will never be standard so DOCUMENT IT so users can work with it, include pip as in a standard install (likely in an admin area). Someone getting a non-standard undocumented feature to work means no more than it can work.

==========

(In reply to elmau from comment #9)
> With LibO 7.2 in W10, pip install correctly again. So, we can close this
> issue.

Why? V7.2 is pre-release. V7.0 is still available. How are users expected to deal with the issue?

LibreOffice 7.2.0 - If you're a technology enthusiast, early adopter or power user, this version is for you!

LibreOffice 7.1.5 - This version is slightly older and does not have the latest features, but it has been tested for longer. For business deployments, we strongly recommend support from certified partners which also offer long-term support versions of LibreOffice.

Available Versions - LibreOffice is available in the following released versions: 7.2.0, 7.1.5, 7.0.6

> PS C:\Program Files\LibreOffice\program> .\python.exe C:\Users\Pruebas\get-pip.py --user

Where is *that* documented? I never have any need for powershell.

==========

(In reply to Ming Hua from comment #7)
> (In reply to flywire from comment #6)
> > pip maintainers consider LibreOffice python install is incomplete because
> > pip should be installed as part of the distribution -
> > https://github.com/pypa/pip/issues/10006#issuecomment-899956947
> Again, I want to point out that the problem description in that ticket seems
> to only apply for LO 7.0 or earlier, from my personal experience.
> 

Problem: Installing packages is essential for more than trivial python use yet there is no documentation

Issues are:
* Clear user documentation should be available. Pip maintainers say their documentation can't be followed because the LO python package doesn't include pip - pip should be part of embedded python.
* It is not uncommon for users to have python installed on their system. How can a user work with the specific version they need to? How does a user even know where LO embedded python is in eg "C:\Program Files\LibreOffice\program\python.exe" or is that "C:\Program Files\LibreOffice\program\python-core-3.8.10\bin", or perhaps "C:\Users\User\AppData\Roaming\Python\Python38\Scripts"?
* Related issue is should LO python be in a venv as in other software where it is embedded?

1. What documentation are you referring to?
2. Version information above. 7.0 is an available version. How are users expected to know how to deal with this issue?

> > Tested on LibreOffice 7.2 (Python 3.8) [LibreOffice 7.0 (Python 3.7) not
> > tested].
> > 
> > Following [Ensure you can run pip from the command
> > line](https://packaging.python.org/tutorials/installing-packages/#id13)
> > > If that still doesn’t allow you to run python -m pip
> > 
> > ```
> > Microsoft Windows [Version 10.0.19043.1165]
> > (c) Microsoft Corporation. All rights reserved.
> > 
> > C:\Program Files\LibreOffice\program>python -m get-pip.py
> > C:\Program Files\LibreOffice\program\python-core-3.8.10\bin\python.exe:
> > Error while finding module specification for 'get-pip.py'
> > (ModuleNotFoundError: __path__ attribute not found on 'get-pip' while trying
> > to find 'get-pip.py')
> Why did you do this?  get-pip.py is the filename of the script, not a python
> module name.  And -m requires a module parameter to follow.  This would
> never work, not on LO's bundled python, nor on the official python.org
> installation.
> 

LO has no docs for installing packages or pip. I followed the link given to the official pip docs.
"And -m ... This would never work" - that's my understanding of the pip docs. Who knows why you chose those commands, I showed my workflow clearly rather than just the commands that worked.

> You should invoke the script directly with "python.exe get-pip.py", like you
> did below.
> 
> > C:\Program Files\LibreOffice\program>python get-pip.py
> > Defaulting to user installation because normal site-packages is not writeable
> Why did this happen?  Did you run the command above with an ordinary user
> without administrative privileges?

I'm an ordinary user and I followed official pip docs. iirc I installed with and without admin rights during testing but I can't recall which one I documented here. Should be without admin rights.
 
> > Collecting pip
> >   Using cached pip-21.2.4-py3-none-any.whl (1.6 MB)
> > Installing collected packages: pip
> >   Attempting uninstall: pip
> >     Found existing installation: pip 21.2.4
> >     Uninstalling pip-21.2.4:
> >       Successfully uninstalled pip-21.2.4
> >   WARNING: The scripts pip.exe, pip3.8.exe and pip3.exe are installed in
> > 'C:\Users\User\AppData\Roaming\Python\Python38\Scripts' which is not on PATH.
> >   Consider adding this directory to PATH or, if you prefer to suppress this
> > warning, use --no-warn-script-location.
> And here the script warned you that you are installing pip inside your home
> directory, which is normally not checked by LO's python.exe.

Again, where are the docs?
 
> > Successfully installed pip-21.2.4
> > ```
> > 
> > I don't know where it found existing installation, it wasn't in the path and
> > that folder was empty until pip was installed. Maybe `get-pip.py` needs to
> > be downloaded to `C:\Program
> > Files\LibreOffice\program\python-core-3.8.10\bin`.
> The get-pip.py can be placed in any folder, just make sure to run it with
> LO's python.  For example
>   > "C:\Program Files\LibreOffice\program\python.exe" get-pip.py
> can be done from any folder that contains get-pip.py.
> 
> Also make sure you run it with an admin account (or at least an account that
> can write to C:\Program Files\LibreOffice\), and things should go smoothly.

*Document it* and make pip part of LO embedded python.
Comment 11 Jan-Marek Glogowski 2021-08-26 11:18:19 UTC
I'll give you some background info, especially for Windows (but also the TDF builds on other platforms).

LO bundles / builds it's own (patched) Python, because the Python UNO bridge (AKA the interface to control LO via Python) is implemented as a C++ shared library (DLL on Windows). I don't know, if that implementation must be done this way or not, and if a Python-only implementation would be possible.
AFAIK it uses CPython memory management functions, which differ between CPython versions, so the only alternative on Windows would be to ship pre-build UNO-Python-DLLs for many Python versions. Nobody wants to implement this. So LO can't rely on upstream Python installers on Win.

And when I did the Windows ARM64 LO port, I updated Python 3.7 to 3.8 and updated the installation details in https://git.libreoffice.org/core/+/b4dfba947768834ffecc09056992019878711c8b%5E!
As you can see it adds a lot of asyncio files, which were missing from LO Python 3.7 install set; quite probably the origin of your reported problem.

For Linux, distros simply build LO with the system python => problem solved.

I don't have any solution for the broken LO 7.0 + Python 3.7; also it's EOL: https://wiki.documentfoundation.org/ReleasePlan/7.0

My general suggestion would be to use LO from a Linux distro, if you need any additional Python modules with less hassle; that seems the most straight forward solution.

Since LO > 7.0 works, as demonstrated by multiple users, I'm closing this as WFM.

(In reply to flywire from comment #10)

General answer: feel free to implement your suggestions / write the docs. LO is a FOSS project (or pay someone to implement it). For documentation see https://wiki.documentfoundation.org/Documentation/Development
Comment 12 flywire 2021-08-26 11:45:46 UTC
Add get-pip.py to the install
Comment 13 Alex Thurgood 2021-09-01 15:43:14 UTC
Can someone tell me how all of this is supposed to work on macOS without invalidating the app bundle ?

I see that pip3.8 is included in the Mac app bundle, but launching it immediately says that it should be updated, and I'm guessing that doing so would either fail, or else cause LO to no longer startup due to failed authentication of the app bundle ?

Would that be the same for any pip modules that I installed ?
Comment 14 Jan-Marek Glogowski 2021-09-06 09:58:49 UTC
(In reply to Alex Thurgood from comment #13)
> Can someone tell me how all of this is supposed to work on macOS without
> invalidating the app bundle ?
> 
> I see that pip3.8 is included in the Mac app bundle, but launching it
> immediately says that it should be updated, and I'm guessing that doing so
> would either fail, or else cause LO to no longer startup due to failed
> authentication of the app bundle ?
> 
> Would that be the same for any pip modules that I installed ?

Maybe it'll work the same way then additional language packs are installed in MacOS. AFAIK that is a big hack already, often confuses users, but generally works?!
I have no idea, if that is still true and don't have a Mac, but that is the info I got from various bugs and mails about this assumed similar problem. Writing a mail to the dev-list should give the most recent info on this topic.
Comment 15 Alex Thurgood 2021-09-07 10:01:45 UTC
(In reply to Jan-Marek Glogowski from comment #14)

 
> Maybe it'll work the same way then additional language packs are installed
> in MacOS. AFAIK that is a big hack already, often confuses users, but
> generally works?!
> I have no idea, if that is still true and don't have a Mac, but that is the
> info I got from various bugs and mails about this assumed similar problem.
> Writing a mail to the dev-list should give the most recent info on this
> topic.

Well at least for pip in LO7152, the update appeared to function without ruining the app bundle. I've also installed a couple of database modules via pip install, and will see if I can get anything useful out of them in a python script running within LO.