AwesomeTTS / awesometts-anki-addon

AwesomeTTS text-to-speech add-on for Anki
GNU General Public License v3.0
481 stars 99 forks source link

Error after updating to latest Anki / Python #319

Open matejdro opened 2 months ago

matejdro commented 2 months ago

Hello,

After updating to the latest Python, addon does not start anymore:

Anki 24.04.1 (ccd9ca1a) (src) (ao)
Python 3.12.3 Qt 6.7.0 PyQt 6.7.0
Platform: Linux-6.8.7-arch1-1-x86_64-with-glibc2.39

When loading AwesomeTTS - Add speech to your flashcards:
Traceback (most recent call last):
  File "/usr/lib/python3.12/site-packages/aqt/addons.py", line 247, in loadAddons
    __import__(addon.dir_name)
  File "/home/matej/.local/share/Anki2/addons21/1436550454/__init__.py", line 42, in <module>
    from . import awesometts  # noqa, pylint:disable=wrong-import-position
    ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/matej/.local/share/Anki2/addons21/1436550454/awesometts/__init__.py", line 32, in <module>
    from . import conversion as to, gui, paths, service
  File "/home/matej/.local/share/Anki2/addons21/1436550454/awesometts/gui/__init__.py", line 31, in <module>
    from .configurator import Configurator
  File "/home/matej/.local/share/Anki2/addons21/1436550454/awesometts/gui/configurator.py", line 21, in <module>
    from locale import format as locale
ImportError: cannot import name 'format' from 'locale' (/usr/lib/python3.12/locale.py). Did you mean: '_format'?
luc-vocab commented 2 months ago

Hi, how did you install Anki, is it with a package in your distribution?

matejdro commented 2 months ago

It's the anki-bin AUR package https://aur.archlinux.org/packages/anki-bin

Jomosoto commented 2 months ago

I'm getting the same error. I installed it from the AUR anki (source) package: https://aur.archlinux.org/packages/anki

luc-vocab commented 2 months ago

It doesn't look like it's an AwesomeTTS issue. The arch package uses the system version of python (3.12) and that probably won't work with Anki. If you'd like to get back to a working version, install the package from ankiweb: https://apps.ankiweb.net/

matejdro commented 2 months ago

Anki works great for me, including a bunch of other add-ons, except for this addon.

Any chance this add on could be updates to new python? It would have to be done eventually anyway, once bundled anki python updates.

junio256 commented 2 months ago

Anki works great for me, including a bunch of other add-ons, except for this addon.

Any chance this add on could be updates to new python? It would have to be done eventually anyway, once bundled anki python updates.

ditto, since AUR is rolling release, many more users can face this issue anytime soon

luc-vocab commented 2 months ago

if I can find a way to fix for both python 3.9 (official python interpreter used by Anki) and python 3.12, I will. Give me a bit of time to look into this.

philippmisof commented 1 month ago

I'm having the same problem. According to Python 3.11's documentation locale.format has been deprecated since Pyhon 3.7 and has been replaced by format_string. It seems it has completely been removed in Python 3.12.

Changing https://github.com/AwesomeTTS/awesometts-anki-addon/blob/b4001692c8542da096612f711d7b6ffc6b50baca/awesometts/gui/configurator.py#L21

to

from locale import format_string as locale

solved the issue for me. But I have not tested it out with other Python versions. But note that also the documentation of 3.9 suggests replacing it with format_string, so I would assume this fix should work from 3.9+.

luc-vocab commented 1 month ago

Thanks a lot for the suggested fix. Give me a day or two to test and i'll merge it.

yacodes commented 1 month ago

Looking forward to the fix!

luc-vocab commented 1 month ago

Sorry I got delayed but i'm definitely planning on fixing this very soon, in the coming days.

luc-vocab commented 1 month ago

I'm not able to test AwesomeTTS with Python 3.12 at all, it crashes on startup for me. I still think it's questionable for the various package maintainers to unilateraly upgrade the python interpreter, when Anki is really only officially tested with Python 3.9. That said I did implement the fix, could someone on Arch or other affected Linux distributions grab the addon file and test it ? https://github.com/Vocab-Apps/anki-awesome-tts/releases/tag/v1.88.2 If it works, I'll publish it on Ankiweb.

luc-vocab commented 1 month ago

I'd also like to ask everyone whether they would consider upgrading to HyperTTS ? It's a better tested, more capable, more modern version of AwesomeTTS: https://ankiweb.net/shared/info/111623432 I just tested it and it's fully compatible with Python 3.12.

yacodes commented 1 month ago

@luc-vocab I would love to move to HyperTTS but it does not work on Arch at all if you want to use Azure or Amazon voices. It fails with Cannot access local variable 'voice' where it is not associated with a value.

luc-vocab commented 1 month ago

@yacodes many thanks for this feedback, if you have a chance could you share the stack trace ? I also need to find a way to test the Arch packages on my setup.

yacodes commented 1 month ago

@luc-vocab Not sure how to do it correctly. Running anki from the terminal and forcing the error to occur shows this:

Qt info: libpng warning: iCCP: known incorrect sRGB profile
2024-05-24 20:26:12,406:WARNING:urllib3.connectionpool: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7fea7c9929c0>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution')': /api/6170140/envelope/
2024-05-24 20:26:12,413:WARNING:urllib3.connectionpool: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7fea7c992ba0>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution')': /api/6170140/envelope/
2024-05-24 20:26:12,421:WARNING:urllib3.connectionpool: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7fea7c992c90>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution')': /api/6170140/envelope/
luc-vocab commented 1 month ago

That output by itself doesn't constitute an error, are Anki and AwesomeTTS coming up properly ?

Khouderchah-Alex commented 1 month ago

@luc-vocab verified that the move from format to format_string works and is good to go.

locale.format was already deprecated in 3.9, so no concerns there about breaking clients on the recommended python version. format_string is basically a superset of format, so current usage should be fine

luc-vocab commented 1 month ago

OK, i've release AwesomeTTS 1.88.2 with the change which fixes this, please let me know if you run into any issues.

Jomosoto commented 1 month ago

Thank you! Works for me now :+1:

yacodes commented 1 month ago

Thanks a lot for this fix! Can confirm that AwesomeTTS is working now.