FHPythonUtils / TStickers

Download sticker packs from Telegram
MIT License
55 stars 7 forks source link

Bug: RuntimeError: Backend could not be loaded #4

Closed difhel closed 2 months ago

difhel commented 6 months ago

Before You Begin

Before proceeding, please make sure to follow these steps:

Issue Details

I am always getting this error when trying to download a stickerpack.

Description

I added my bot token to env, then

poetry run tstickers -p https://t.me/addstickers/UtyaDuck
INFO     | ============================================================
INFO     | Starting to scrape "UtyaDuck" ..
INFO     | Time taken to scrape 40 stickers - 0.076s
INFO     | 
INFO     | ------------------------------------------------------------
INFO     | Starting download of "utyaduck" into downloads/utyaduck
INFO     | Time taken to download 40 stickers - 0.084s
INFO     | 
INFO     | ------------------------------------------------------------
INFO     | -> Cache miss for UtyaDuck!
INFO     | Converting stickers "UtyaDuck"...
Traceback (most recent call last):
  File "/home/mf/tools/.venv/bin/tstickers", line 8, in <module>
    sys.exit(cli())
             ^^^^^
  File "/home/mf/tools/.venv/lib/python3.11/site-packages/tstickers/cli.py", line 100, in cli
    downloader.convertPack(
  File "/home/mf/tools/.venv/lib/python3.11/site-packages/tstickers/downloader.py", line 272, in convertPack
    converted = convertedTgs = convertAnimated(
                               ^^^^^^^^^^^^^^^^
  File "/home/mf/tools/.venv/lib/python3.11/site-packages/tstickers/convert.py", line 146, in convertAnimated
    converted = convertMap[backend](swd, threads, frameSkip, scale)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mf/tools/.venv/lib/python3.11/site-packages/tstickers/convert.py", line 27, in convertAnimatedFunc
    raise RuntimeError(msg)
RuntimeError: Backend could not be loaded

System Information

Please provide the following additional information about your system or environment:

vanenshi commented 6 months ago

same here

FredHappyface commented 5 months ago

Needs some thinking on how best to approach this as tstickers supports multiple backends

For now, try the following:

pip install tstickers[rlottie-python]
difhel commented 5 months ago

@FredHappyface I tried this, still the same error.

FredHappyface commented 5 months ago

Ah that's no good. I'll take a look at this as soon as I've some free time!

itpey commented 4 months ago

Solution for RuntimeError: Backend could not be loaded

Solution Steps:

1. Install tstickers Package:

pip install tstickers

2. Install Required Dependencies:

pip install "rlottie-python>=1.3.3,<2"
pip install "pyrlottie>=2024.0.1,<2026"
pip install "loguru>=0.7.2,<2"

3. Create and Set Up Working Directory:

4. Run the Sticker Conversion Command in mystickers:

Navigate to the mystickers directory and run:

cd mystickers
tstickers --pack https://t.me/addstickers/DonutTheDog
difhel commented 4 months ago

Hello! After applying your fix I got this error:

(telegram-stickers-py3.12) mark@Marks-MacBook-Pro telegram-stickers % tstickers -p https://t.me/addstickers/AnimatedEmojies
INFO     | ============================================================
INFO     | Starting to scrape "AnimatedEmojies" ..
INFO     | Time taken to scrape 598 stickers - 41.604s
INFO     | 
INFO     | ------------------------------------------------------------
INFO     | Starting download of "animatedemojies" into downloads/animatedemojies
Traceback (most recent call last):
  File "/Users/mark/Library/Caches/pypoetry/virtualenvs/telegram-stickers-usHqk-q4-py3.12/bin/tstickers", line 8, in <module>
    sys.exit(cli())
             ^^^^^
  File "/Users/mark/Library/Caches/pypoetry/virtualenvs/telegram-stickers-usHqk-q4-py3.12/lib/python3.12/site-packages/tstickers/cli.py", line 95, in cli
    _ = downloader.downloadPack(stickerPack)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mark/Library/Caches/pypoetry/virtualenvs/telegram-stickers-usHqk-q4-py3.12/lib/python3.12/site-packages/tstickers/downloader.py", line 231, in downloadPack
    downloads += 1 if i.result() > 0 else 0
                      ^^^^^^^^^^
  File "/usr/local/Cellar/python@3.12/3.12.3/Frameworks/Python.framework/Versions/3.12/lib/python3.12/concurrent/futures/_base.py", line 449, in result
    return self.__get_result()
           ^^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/python@3.12/3.12.3/Frameworks/Python.framework/Versions/3.12/lib/python3.12/concurrent/futures/_base.py", line 401, in __get_result
    raise self._exception
  File "/usr/local/Cellar/python@3.12/3.12.3/Frameworks/Python.framework/Versions/3.12/lib/python3.12/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mark/Library/Caches/pypoetry/virtualenvs/telegram-stickers-usHqk-q4-py3.12/lib/python3.12/site-packages/tstickers/downloader.py", line 199, in downloadSticker
    return path.write_bytes(self.session.get(link).content)
                            ^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mark/Library/Caches/pypoetry/virtualenvs/telegram-stickers-usHqk-q4-py3.12/lib/python3.12/site-packages/requests_cache/session.py", line 126, in get
    return self.request('GET', url, params=params, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mark/Library/Caches/pypoetry/virtualenvs/telegram-stickers-usHqk-q4-py3.12/lib/python3.12/site-packages/requests_cache/session.py", line 182, in request
    return super().request(method, url, *args, headers=headers, **kwargs)  # type: ignore
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mark/Library/Caches/pypoetry/virtualenvs/telegram-stickers-usHqk-q4-py3.12/lib/python3.12/site-packages/requests/sessions.py", line 589, in request
    resp = self.send(prep, **send_kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mark/Library/Caches/pypoetry/virtualenvs/telegram-stickers-usHqk-q4-py3.12/lib/python3.12/site-packages/requests_cache/session.py", line 217, in send
    cached_response = self.cache.get_response(actions.cache_key)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mark/Library/Caches/pypoetry/virtualenvs/telegram-stickers-usHqk-q4-py3.12/lib/python3.12/site-packages/requests_cache/backends/base.py", line 78, in get_response
    response = self.responses[self.redirects[key]]
                              ~~~~~~~~~~~~~~^^^^^
  File "/Users/mark/Library/Caches/pypoetry/virtualenvs/telegram-stickers-usHqk-q4-py3.12/lib/python3.12/site-packages/requests_cache/backends/sqlite.py", line 311, in __getitem__
    cur = con.execute(f'SELECT value FROM {self.table_name} WHERE key=?', (key,))
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
sqlite3.InterfaceError: bad parameter or other API misuse

I think this is an unrelated issue connected with caching, as I often encourage it when redownloading packs. After I used rm -rf ./downloads, I encountered another issue:

(telegram-stickers-py3.12) mark@Marks-MacBook-Pro telegram-stickers % tstickers -p https://t.me/addstickers/AnimatedEmojies
INFO     | ============================================================
INFO     | Starting to scrape "AnimatedEmojies" ..
INFO     | Time taken to scrape 598 stickers - 0.599s
INFO     | 
INFO     | ------------------------------------------------------------
INFO     | Starting download of "animatedemojies" into downloads/animatedemojies
INFO     | Time taken to download 598 stickers - 0.810s
INFO     | 
INFO     | ------------------------------------------------------------
INFO     | -> Cache miss for AnimatedEmojies!
INFO     | Converting stickers "AnimatedEmojies"...
Traceback (most recent call last):
  File "/Users/mark/Library/Caches/pypoetry/virtualenvs/telegram-stickers-usHqk-q4-py3.12/bin/tstickers", line 8, in <module>
    sys.exit(cli())
             ^^^^^
  File "/Users/mark/Library/Caches/pypoetry/virtualenvs/telegram-stickers-usHqk-q4-py3.12/lib/python3.12/site-packages/tstickers/cli.py", line 100, in cli
    downloader.convertPack(
  File "/Users/mark/Library/Caches/pypoetry/virtualenvs/telegram-stickers-usHqk-q4-py3.12/lib/python3.12/site-packages/tstickers/downloader.py", line 272, in convertPack
    converted = convertedTgs = convertAnimated(
                               ^^^^^^^^^^^^^^^^
  File "/Users/mark/Library/Caches/pypoetry/virtualenvs/telegram-stickers-usHqk-q4-py3.12/lib/python3.12/site-packages/tstickers/convert.py", line 146, in convertAnimated
    converted = convertMap[backend](swd, threads, frameSkip, scale)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mark/Library/Caches/pypoetry/virtualenvs/telegram-stickers-usHqk-q4-py3.12/lib/python3.12/site-packages/tstickers/convert_pyrlottie.py", line 55, in convertAnimated
    converted += doConvMultLottie(
                 ^^^^^^^^^^^^^^^^^
  File "/Users/mark/Library/Caches/pypoetry/virtualenvs/telegram-stickers-usHqk-q4-py3.12/lib/python3.12/site-packages/tstickers/convert_pyrlottie.py", line 48, in doConvMultLottie
    asyncio.get_event_loop().run_until_complete(
  File "/usr/local/Cellar/python@3.12/3.12.3/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/base_events.py", line 687, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/Users/mark/Library/Caches/pypoetry/virtualenvs/telegram-stickers-usHqk-q4-py3.12/lib/python3.12/site-packages/pyrlottie/__init__.py", line 480, in convMultLottie
    _ = [destFiles.add(destFile) for destFile in await future]
                                                 ^^^^^^^^^^^^
  File "/usr/local/Cellar/python@3.12/3.12.3/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/tasks.py", line 631, in _wait_for_one
    return f.result()  # May raise f.exception().
           ^^^^^^^^^^
  File "/Users/mark/Library/Caches/pypoetry/virtualenvs/telegram-stickers-usHqk-q4-py3.12/lib/python3.12/site-packages/pyrlottie/__init__.py", line 535, in convSingleLottie
    binDir = _getBinDir()
             ^^^^^^^^^^^^
  File "/Users/mark/Library/Caches/pypoetry/virtualenvs/telegram-stickers-usHqk-q4-py3.12/lib/python3.12/site-packages/pyrlottie/__init__.py", line 200, in _getBinDir
    raise OSError(msg)
OSError: Sorry, your environment is not currently supported! system='Darwin' machine='x86_64'
Task exception was never retrieved

[...many repeats of this error]
xhsgg12302 commented 4 months ago

Solution for RuntimeError: Backend could not be loaded

Solution Steps:

1. Install tstickers Package:

pip install tstickers

2. Install Required Dependencies:

pip install "rlottie-python>=1.3.3,<2"
pip install "pyrlottie>=2024.0.1,<2026"
pip install "loguru>=0.7.2,<2"

3. Create and Set Up Working Directory:

  • Create a directory named mystickers.
  • Navigate to the mystickersdirectory.
  • Create a file named env.txt and place your bot token inside this file.

4. Run the Sticker Conversion Command in mystickers:

Navigate to the mystickers directory and run:

cd mystickers
tstickers --pack https://t.me/addstickers/DonutTheDog

that's work for me ,thx :+1:

TomerGamerTV commented 3 months ago

Its working but its failing to convert anything

Edit: After letting it run for a while it seems like for some reason it does convert some sticker packs but doesn't others..

HaiLinWang commented 2 months ago

Check the pyrlottie documentation does not support the darwin_x86_64 and darwin_arm64 .conversion stickers can specify rlottie-python or pyrlottie You can use rlottie-python to try the conversion. For example, python -m tstickers --backend rlottie-python

FredHappyface commented 2 months ago

Hey taking a look at this today to make this all a bit more user friendly! Now the tstickers package will install with pyrlottie regardless of the extra chosen. Bit frustrating that python doesn't handle this particularly nicely. Also the cli will provide a more helpful error message in the case of using an uninstalled backend. For example in testing

$ tstickers -b rlottie-python
ERROR    | !! rlottie-python is not installed! Install with "pip install rlottie-python"

Apologies this has taken so long to get around to! I'll have a look at the pyrlottie lib later to see what I can do around the darwin support. Broadly the lottie-python lib has broader os support than this lib but seems to be a little less performant as a backend (due to the use of python-pillow oddly)

I'll also write some documentation on this as I realise it's a bit broken and confusing at the moment (also fixing as much of the broken as possible)

FredHappyface commented 2 months ago

@FredHappyface I tried this, still the same error.

Hmm really strange. Ive tested locally and I suspect this is largely down to unclear documentation as things behave largely as expected. Ie

PS C:\Users\Dell> py -m venv venv
PS C:\Users\Dell> .\venv\Scripts\activate.ps1
(venv) PS C:\Users\Dell> py -m pip install tstickers[pyrlottie]
...
Installing collected packages: win32-setctime, urllib3, typing-extensions, six, platformdirs, Pillow, packaging, numpy, idna, colorama, charset-normalizer, certifi, attrs, url-normalize, requests, loguru, emoji, deprecation, cattrs, requests-cache, pyrlottie, tstickers
...

stickers -b pyrlottie works as expected

stickers -b lottie-python throws an error

As noted above, I've changed the default install to include pyrlottie going forwards (releasing later today) so not specifying a backend will work on a vanilla install :)

FredHappyface commented 2 months ago

Its working but its failing to convert anything

Edit: After letting it run for a while it seems like for some reason it does convert some sticker packs but doesn't others..

Hi can you create a new issue for this? And can you provide the link to the sticker pack not working/ or a stacktrace so I can investigate this? Thanks :)

FredHappyface commented 2 months ago

Fixed in https://github.com/FHPythonUtils/TStickers/releases/tag/2024.1.3