@dae excuse me ! Here are example code
# or import
error output as follows
File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\lib\site-packages\anki\_backend\__init__.py", line 14, in <module>
File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\lib\site-packages\anki\lang.py", line 16, in <module>
TR = anki._backend.LegacyTranslationEnum
AttributeError: module 'anki' has no attribute '_backend'
Is this a bug ? or am I wrong with some code?
Any advice would be appreciated!
Maybe your versions of the aqt and anki modules do not match.
I use command
pip install anki==2.1.46;
Is there version incompitabily in it ?
And then,In my Windows cmd shell,run
in version 2.1.44 and older,there is no problem.
the error appears,I dont know whether it’s my computer problem or not?
I find the reason why the error appears by compare latest version with 2.1.44.
in anki init.py,there is no code,so I copy some code into it,and it works.
from anki.collection import Collection
__all__ = ["Collection"]
Thanks for your reply! will this be added into init.py file next time?
__init__.py file can’t be changed back, as it is used as a namespace now, but your file should work correctly if you put
from anki.collection import Collection at the top of it.
I also encountered this error, and you can fix it by importing
The reason is because
anki.lang, which has the line
TR = anki._backend.LegacyTranslationEnum. But because
anki._backend module hasn’t finished initializing,
anki._backend attribute hasn’t been set yet.
However the other way around works, because
anki.lang is not used in
anki.lang finishes initializing. (Because it’s used inside functions that don’t get run before
anki.lang is initialized)
UPDATE: Also, for other
anki.module import failing because of their order, importing
anki.collection first like @ankibaby has suggested is quite useful in importing them in the correct order!