radius
February 12, 2024, 10:10am
1
My python version is 3.11.2 and my OS is Debian.
I installed the anki module using:
pip install anki
When running this code:
from anki.importing.apkg import AnkiPackageImporter
apkg_path = "/home/username/Downloads/test.apkg"
importer = AnkiPackageImporter(apkg_path)
importer.run()
I am getting this error:
ImportError: cannot import name 'NotetypeDict' from partially initialized module 'anki.models' (most likely due to a circular import)
I believe this is a bug, though I may be wrong.
abdo
February 12, 2024, 1:32pm
2
It’s a bug. I sent a fix:
ankitects:main
← abdnh:circular-import
opened 01:30PM - 12 Feb 24 UTC
https://forums.ankiweb.net/t/bug-report-python-anki-module-circular-import/41026
Note that you’ll need to add this before .run() for the code to work:
from anki.lang import set_lang
set_lang("en_US")
But I recommend using the new importing API instead. See an example here:
That’s the legacy importer, which will be removed in the future. The following code should be used instead, though it will only work if you run for git or wait until the next beta build.
from anki.collection import ImportAnkiPackageOptions, ImportAnkiPackageRequest
col.import_anki_package(
ImportAnkiPackageRequest(
package_path="/path/foo.apkg",
options=ImportAnkiPackageOptions(
with_scheduling=True, with_deck_conf…
radius
February 12, 2024, 7:13pm
3
Thank you very much!
I am now using this code:
from anki.collection import ImportAnkiPackageRequest, Collection
collection = Collection("/home/username/.var/app/net.ankiweb.Anki/data/Anki2/User 1/collection.anki2")
collection.import_anki_package(
ImportAnkiPackageRequest(
package_path="/home/username/Downloads/test.apkg"
)
)
And it works perfectly!