mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 14:02:21 -04:00
![]() While something we probably don't want to encourage much of, this may enable some previously-unshared add-ons. https://forums.ankiweb.net/t/bundling-numpy-in-an-add-on/62669/5 The 'uv add' command is transaction, so if an add-on tries to inject incompatible dependencies into the environment, the venv will be left as-is. And each Anki upgrade/downgrade resets the requirements, so the requested packages shouldn't cause errors down the line. Sample add-on: import subprocess from aqt import mw from aqt.operations import QueryOp from aqt.qt import QAction from aqt.utils import showInfo def ensure_spacy(col): print("trying to import spacy") try: import spacy print("successful import") return except Exception as e: print("error importing:", e) print("attempting add") try: from aqt.package import add_python_requirements as add except Exception as e: raise Exception(f"package unavailable, can't install: {e}") # be explicit about version, or Anki beta users will get # a beta wheel that may break (success, output) = add(["spacy==3.8.7", "https://github.com/explosion/spacy-models/releases/download/ko_core_news_sm-3.8.0/ko_core_news_sm-3.8.0-py3-none-any.whl"]) if not success: raise Exception(f"adding failed: {output}") print("success") # alterantively: # from aqt.package import venv_binary # subprocess.run([venv_binary("spacy"), "download", "ko_core_news_sm"], check=True) # print("model added") # large packages will freeze for a while on first import on macOS import spacy print("spacy import successful") def activate_spacy(): def on_success(res): mw.progress.single_shot(1000, lambda: showInfo("Spacy installed")) QueryOp(parent=mw, op=ensure_spacy, success=on_success).with_progress("Installing spacy...").run_in_background() action = QAction("Activate Spacy", mw) action.triggered.connect(activate_spacy) mw.form.menuTools.addAction(action) |
||
---|---|---|
.. | ||
browser | ||
data | ||
forms | ||
import_export | ||
operations | ||
qt | ||
__init__.py | ||
_macos_helper.py | ||
about.py | ||
addcards.py | ||
addons.py | ||
ankihub.py | ||
changenotetype.py | ||
clayout.py | ||
colors.py | ||
customstudy.py | ||
dbcheck.py | ||
debug_console.py | ||
deckbrowser.py | ||
deckchooser.py | ||
deckconf.py | ||
deckdescription.py | ||
deckoptions.py | ||
editcurrent.py | ||
editor.py | ||
emptycards.py | ||
errors.py | ||
exporting.py | ||
fields.py | ||
filtered_deck.py | ||
flags.py | ||
gui_hooks.py | ||
importing.py | ||
legacy.py | ||
log.py | ||
main.py | ||
mediacheck.py | ||
mediasrv.py | ||
mediasync.py | ||
modelchooser.py | ||
models.py | ||
mpv.py | ||
notetypechooser.py | ||
overview.py | ||
package.py | ||
preferences.py | ||
profiles.py | ||
progress.py | ||
props.py | ||
py.typed | ||
reviewer.py | ||
schema_change_tracker.py | ||
sound.py | ||
stats.py | ||
studydeck.py | ||
stylesheets.py | ||
switch.py | ||
sync.py | ||
tagedit.py | ||
taglimit.py | ||
taskman.py | ||
theme.py | ||
toolbar.py | ||
tts.py | ||
undo.py | ||
update.py | ||
url_schemes.py | ||
utils.py | ||
webview.py | ||
widgetgallery.py | ||
winpaths.py |