Python 3 script in LibreELEC 10

  • Probably not the right place to ask, but I am too tired to open a new thread now.

    There is a python3 script I want to run on my le 10 x64 installation and it needs the requests library (python3-requests is the name of the package in debian).

    And it fails to run because this python library is missing. Pip is also missing, so I can not install it by hand. Can I somehow use kodi's script.module.requests to run it?

  • Go to Best Answer
  • Create and use:

    Bash: pythonwrapper
    #!/bin/sh
    PYTHONPATH=
    for addon in /storage/.kodi/addons/*/lib /storage/.kodi/addons/*/libs /usr/lib/kodi/addons/*/lib; do
      [ -d "${addon}" ] && PYTHONPATH="${PYTHONPATH:+${PYTHONPATH}:}${addon}"
    done
    export PYTHONPATH
    exec /usr/bin/python "$@"
  • Klojum

    Please excuse my "lazyness". The past 2 days were exhausting for me. I was up at 5 am (on sunday too) and had to go through the day with all my nerves hitting "peak performance" for at least 12 hours straight.

    mglae

    Great! Now can I use it like so?

    Code
    pythonwrapper myscript.py

    I will test it in 4+ hours.

    Edited once, last by jim_p (September 28, 2021 at 11:01 AM).

  • Almost worked! Actually, the entire idea and the shell script worked as it should. If only the python script did not have that extra dependency for the the tqdm library :(

    Python
    from tqdm import tqdm
    ModuleNotFoundError: No module named 'tqdm'

    I will try removing the offending line and see how it goes...

  • For a python only lib - not needing any external dependencies or including e.g. C/C++ code - the source is the lib. Try copying the files below the "tqdm" directory.

    However creating a LE python lib addon is the correct way to go.

  • I know this is an old thread but it does refer to Libreelec 10 which I am running and the exact module I need python "requests". Can anyone help me to understand how to make this python wrapper work?

    Is the "tqdm" a dependency for requests?

    Thanks

  • Tqdm is a python library for progress bars, nothing more.

    The requests library exists as a kodi addon in the main repo, so you can just ssh the libreelec system and run

    Code
    kodi-send --action="InstallAddon(script.module.requests)"

    A prompt will appear on kodi, as shown in the screenshot below, so you just press yes there.

    The reason for the above is that, since kodi 17, search does not return results for addons of the "script.module.*" family. If it did, you could just search for it from within kodi and install it as any other addon.

  • Nothing happens when i use that command at ssh terminal, but I already have requests installed.

    I can confirm it is an installed dependency for some addons I have installed. I do not see a way to install it directly.

    In fact, searching for addon called "requests" causes Kodi to crash, but searching for other addons does not. I think that is a bug.

    Code
     python3 myscript.py
    Traceback (most recent call last):
      File "myscript.py", line 4, in <module>
        import requests
    ModuleNotFoundError: No module named 'requests'

    Edited 2 times, last by tekno (July 7, 2022 at 1:36 AM).

  • Ok so here is what I did and this worked!

    I copied the "wrapper" script above.

    Bash
    #!/bin/sh
    PYTHONPATH=
    for addon in /storage/.kodi/addons/*/lib /storage/.kodi/addons/*/libs /usr/lib/kodi/addons/*/lib; do
      [ -d "${addon}" ] && PYTHONPATH="${PYTHONPATH:+${PYTHONPATH}:}${addon}"
    done
    export PYTHONPATH
    exec /usr/bin/python "$@"

    Saved it as pythonwrapper.sh then made it executable

    from the directory where the pythonwrapper.sh file is...

    Code
    chmod +x pythonwrapper.sh

    then I executed

    Code
    ./pythonwrapper.sh .kodi/frndlytv/myscript.py --PORT 8080 --PARAMETER1 "ABC" --PARAMETER2 "XYZ"


    and it worked!

  • Nothing happens when i use that command at ssh terminal, but I already have requests installed.

    About that. Yes, kodi will not show the dialog box if the addon is already installed, even if it is installed and deactivated. It will just ignore the "request" to install it.

  • I suspect that one of the addons I have installed is a cryptography module , but not sure. Maybe this one?

    script.module.cryptolib

    ~/.kodi/addons/script.module.cryptolib # ls -l

    total 28

    -rw-r--r-- 1 root root 1076 Nov 18 2019 LICENSE

    -rw-r--r-- 1 root root 316 Nov 18 2019 README.md

    -rw-r--r-- 1 root root 571 Nov 18 2019 addon.xml

    -rw-r--r-- 1 root root 136 Nov 18 2019 changelog.txt

    -rw-r--r-- 1 root root 7237 Nov 18 2019 icon.png

    drwxr-xr-x 6 root root 4096 Nov 18 2019 lib

    ~/.kodi/addons/script.module.cryptolib/lib # ls -l

    total 44

    drwxr-xr-x 7 root root 4096 Feb 15 2020 Crypto

    -rw-r--r-- 1 root root 2648 Nov 18 2019 binascii_plus.py

    drwxr-xr-x 8 root root 4096 Feb 15 2020 cryptopy

    drwxr-xr-x 2 root root 4096 Nov 18 2019 fmath

    -rw-r--r-- 1 root root 24483 Nov 18 2019 pyblowfish.py

    drwxr-xr-x 2 root root 4096 Nov 18 2019 rsa

    and they go on from there...

  • I do not have such a folder in there, neither on my pc (kodi 19 on x64 linux), nor on the libreelec x64 installation.

    The same applies to script.module.* stuff that is under /usr/share/kodi/addons/.