mortii / anki-morphs

A MorphMan fork rebuilt from the ground up with a focus on simplicity, performance, and a codebase with minimal technical debt.
https://mortii.github.io/anki-morphs/
Mozilla Public License 2.0
47 stars 6 forks source link

spaCy Morphimizers Not Shown #234

Closed drkthomp closed 1 month ago

drkthomp commented 1 month ago

Describe the bug

I installed spaCy morphimizers as per the instructions in the guide but they do not show up in Anki after restarting. Notable is that the Mecab morphimizer does.

Steps to reproduce the behavior

cd ~/.local/share/Anki2/addons21/
python3.12 -m venv spacyenv
source spacyenv/bin/activate
python -m pip install --upgrade pip setuptools wheel
python -m pip install --upgrade spacy six
python -m spacy download ja_core_news_lg
python -m spacy download da_core_news_lg
python -m spacy download es_core_news_md
deactivate

Restarting Anki and looked at morphimizers, but it is not shown.

Expected behavior

The spaCy morphimizers should be shown in ankimorphs upon restart.

Screenshots

2024-05-18T10:27:22,946961210+02:00

My setup

Additional Info

spAcy info:

============================== Info about spaCy ==============================

spaCy version    3.7.4                         
Location         /home/dranion/.local/share/Anki2/addons21/spacyenv/lib/python3.12/site-packages/spacy
Platform         Linux-6.8.9-zen1-2-zen-x86_64-with-glibc2.39
Python version   3.12.3                        
Pipelines        da_core_news_lg (3.7.0), ja_core_news_lg (3.7.0), xx_sent_ud_sm (3.7.0), es_core_news_md (3.7.0)
mortii commented 1 month ago

Weird, it looks correct...

Could you add some debugging print statements here: https://github.com/mortii/anki-morphs/blob/f04cd88a7122f57460ec4e1190c7d3ad009ed2ca/ankimorphs/spacy_wrapper.py#L334

e.g.:

spacy_path = os.path.join(mw.pm.addonFolder(), "spacyenv")
print(f"spacy_path: {spacy_path}")

When you run anki from the terminal and try to change morphemizer you should see the output.

EDIT:

Could you add some debugging print statements here:

make these change in the local file found in ~/.local/share/Anki2/addons21/472573498/spacy_wrapper.py

drkthomp commented 1 month ago

spacy_path: /home/dranion/.local/share/Anki2/addons21/spacyenv

drkthomp commented 1 month ago

It is hitting an exception at some point

spacy_path: /home/dranion/.local/share/Anki2/addons21/spacyenv
win is not true
Exception module not found
          spacy_path = os.path.join(mw.pm.addonFolder(), "spacyenv")
            print(f"spacy_path: {spacy_path}")

            if is_win is True:
                print("win is true")
                spacy_bin_path = os.path.join(spacy_path, "Scripts")
                spacy_site_packages_path = os.path.join(
                    spacy_path, "Lib", "site-packages"
                )
            else:
                print("win is not true")
                spacy_bin_path = os.path.join(spacy_path, "bin")
                spacy_site_packages_path = os.path.join(
                    spacy_path, "lib", "python3.9", "site-packages"
                )

            sys.path.append(spacy_bin_path)
            sys.path.append(spacy_site_packages_path)
            updated_python_path = True

        import spacy.util  # pylint:disable=import-outside-toplevel
        print(f"models: {spacy.util.get_installed_models()}")
        print([f"{model_name}" for model_name in spacy.util.get_installed_models()])
        return [f"{model_name}" for model_name in spacy.util.get_installed_models()]
    except ModuleNotFoundError:
        print("Exception module not found")
        # spacy not installed
        return []
Tartee commented 1 month ago

I had the same issue and was able to fix it. I am using anki-bin 24.04.1-1 (with python 3.12) and had to change

https://github.com/mortii/anki-morphs/blob/f04cd88a7122f57460ec4e1190c7d3ad009ed2ca/ankimorphs/spacy_wrapper.py#L344

to use python3.12 instead of python3.9. Maybe there's a way to fetch anki's running version of python and use that directly instead of hardcoding a version?

Edit: there is! using f'python{sys.version_info.major}.{sys.version_info.minor}' should work

drkthomp commented 1 month ago

Yes, I just attempted that and it also fixed it for me. Seems like it is the hardcoding.

mortii commented 1 month ago

@Tartee My goodness, you're a hero! I'll patch it and push a hotfix asap, thanks!

mortii commented 1 month ago

Released in 2.2.5. Let me know if it didn't work or is bugged in any way :)

github-actions[bot] commented 1 month ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.