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
48 stars 6 forks source link

spacy installation instructions #165

Closed mortii closed 4 months ago

mortii commented 4 months ago

@mortii Do you have to install and use exactly Python 3.9 as hardcoded in the documentation currently because AnkiMorphs uses that? Or use the version that your Anki shows in the about info (the same as system python for me on Arch and the anki-bin AUR package)? Or can you just use any version newer than 3.9 or newer than what Anki uses, even if your Anki binary uses an older version for example?

I am not sure of the mechanism behind it, which python code requires and uses the library.

If it should match the Python version Anki uses, maybe that should be adapted in the installation instructions or if it is 3.9 every time, maybe it could be made clearer that this is because of the plugin, and you should not change it, even if your Anki uses a newer version? That would clear up some confusion for me (and maybe others) I think.

Originally posted by @xuiqzy in https://github.com/mortii/anki-morphs/issues/118#issuecomment-1969887787

mortii commented 4 months ago

@xuiqzy Since Anki uses python 3.9.15, spacy has to be installed using a python 3.9.x version. The python packaging system is very particular about using the same minor version, for better or worse.

IIRC they don't upgrade the Anki python version because the build tools they use don't support it, so that is why I 'hardcoded' the python version in the guide and linked specifically to the last released installer of python 3.9.

Does that make sense? If so, which part of that do you think I should add to the guide? Thanks!

EDIT: I guess it is more precise to say: Anki uses 3.9, therefore AnkiMorphs uses 3.9, therefore spacy has to be installed with 3.9.

xuiqzy commented 4 months ago

Thanks for making the new issue and your quick answer. My desktop Anki (installed via anki-bin package from Arch Linux AUR) says

Version ⁨23.12.1 (1a1d4d54)⁩
Python 3.11.7 Qt 6.6.2 PyQt 6.6.1

which is exactly my system Python version (it also doesn't require a specific python version in the package but just the current version of python in the repository). So, is this wrong and it still uses python 3.9 or would I have to use 3.11 then? And therefore, could it be a different version for different people (that installed it like me)?

From reading the development guide on the Anki Desktop Github, it seems like my setup is an unsupported setup, because it doesn't use python 3.9, is that correct?

EDIT: But from reading the PyPI page of Anki Desktop, it is marked as python >= 3.9. EDIT2: Also relevant: https://betas.ankiweb.net/#via-pypipip

mortii commented 4 months ago

@xuiqzy Ah, you are running a non-standard Anki build, I see why this would be confusing then.

So basically, you have to install spacy with the same python version that Anki uses, in your case 3.11.

This definitely throws a wrench into the current guide... Give me a sec to come up with a proposal for a more general approach.

mortii commented 4 months ago

Okay, here is my proposal:


There is, unfortunately, no super simple way to integrate spaCy with Anki, so we have to perform a little bit of terminal magic. This is because spaCy has a relatively large size (usually ~400 MB), so it can't be included as part of AnkiMorphs itself.


Another problem is that we have to install spaCy with the same python version that Anki uses, which is python 3.9. This version of python is considered outdated, further complicating the process somewhat.

Note: If you downloaded Anki from their website, it will be using Python 3.9. However, if you are using a non-standard Anki build (e.g. anki-bin from AUR), that might not be the case. To check which python version your Anki is using, go to Help -> About, and you will find something like this: Python 3.9.15 Qt 6.6.1 PyQt 6.6.1
Because of the way the python packaging system works, we have to install spaCy with a python version that has the same first two number groups, i.e. if your Anki shows Python 3.11.xx, you can install spaCy using any Python 3.11.yy version.
The rest of this guide assumes Anki uses Python 3.9, but if that is not the cause, then substitute 3.9 in the terminal commands with whatever your Anki is using.


@xuiqzy any suggestions for making that better?

xuiqzy commented 4 months ago

Ahh that makes sense, thanks.

Looks good! I would just mention before the note that this is only for builds downloaded from the website, so people do read the note if they didn't download from the official site and can skip it if they didn't. Something like:

"Another problem is that we have to install spaCy with the same Python version that your installation of Anki uses. If you downloaded Anki from their official website, that is Python 3.9 as of early 2024 (It should show 3.9.x in Help -> About). If you installed it differently or it shows something else as the Python version, please read the note below. Additionally, Python 3.9 is considered outdated, further complicating the process somewhat.

The note follows here..."

I wonder if it could break if the system Python package is updated and Anki uses a newer Python version then. You would ideally reinstall spaCy in a new virtual environment then and delete the old one I guess.

MichaelPetre commented 4 months ago

Also the spacy install instructions for windows should include the requirement for https://learn.microsoft.com/en-us/cpp/windows/latest-supported-vc-redist?view=msvc-170#latest-microsoft-visual-c-redistributable-version

mortii commented 4 months ago

Looks good! I would just mention before the note that this is only for builds downloaded from the website, so people do read the note if they didn't download from the official site and can skip it if they didn't.

@xuiqzy good idea, thanks!

I wonder if it could break if the system Python package is updated and Anki uses a newer Python version then. You would ideally reinstall spaCy in a new virtual environment then and delete the old one I guess.

Yeah, you are completely right; it would break, and you would have to make a new virtual environment or update it. I don't know if it is worth mentioning though--the guide is already pretty verbose and intimidating, and historically this doesn't happened very often (for the standard build anyway).

Also the spacy install instructions for windows should include the requirement for https://learn.microsoft.com/en-us/cpp/windows/latest-supported-vc-redist?view=msvc-170#latest-microsoft-visual-c-redistributable-version

@MichaelPetre oh that is interesting, did you get a bug related to that?

mortii commented 4 months ago

@xuiqzy just to confirm, did you successfully install spacy with the new amendments? I don't want to update the guide with potentially false info.

mortii commented 4 months ago

I'll just assume it works. Correct me if I'm wrong.

@MichaelPetre I don't know how prevalent any errors related to that would be, it's also hard to give any steps without knowing the potential errors one might encounter, so I'll wait with adding it to the guide until someone provides an error/bug report.

Thanks for all the feedback!

github-actions[bot] commented 4 months 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.