pypi anki prevents loading database in desktop app

well's Avatar

well

16 May, 2020 05:36 PM

Hi Damien,

Thank you for adding anki to pypi!
It is great to have the python package readily available.

I'm using anki 2.1.26 from pypi.
By itself, this python package is working with all of my existing scripts.

However, after I open a Collection with a python script, I am then unable to open the Anki Desktop app.
After running a python script successfully, when I open the Anki Desktop app I get the following error message:

Anki was unable to open your collection file. If problems persist after restarting your computer, please use the Open Backup button in the profile manager.

Debug info:
Traceback (most recent call last):
  File "aqt/main.py", line 441, in loadCollection
  File "aqt/main.py", line 462, in _loadCollection
  File "anki/storage.py", line 59, in Collection
  File "anki/collection.py", line 101, in __init__
  File "anki/collection.py", line 196, in load
  File "json/__init__.py", line 357, in loads
  File "json/decoder.py", line 337, in decode
  File "json/decoder.py", line 355, in raw_decode
  json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

I then have to load my collection from a backup.

This error did not happen with previous versions of the python anki package (previous 2.1 versions that existed prior to it being on pypi).
So, I'm not sure if this is a bug with the v2.1.26 python package, or if I am closing the Collection incorrectly.

Example python script to open my collection:

import os  
from anki import Collection

## Open the Anki collection
PROFILE_HOME = os.path.expanduser("~/.local/share/Anki2/User 1")  
cpath = os.path.join(PROFILE_HOME, "collection.anki2")  
col = Collection(cpath)

col.close()  
<pre><code>
Thanks</code>
</pre>
  1. 1 Posted by well on 16 May, 2020 06:04 PM

    well's Avatar

    Good news.

    Updating the Anki Desktop app to v2.1.26 fixed my issue, everything is now working as expected.

    I had been using the Anki Desktop version 2.1.22, which could not open my collection after I had touched the collection with the python v2.1.26 package.
    The recent changes to db.py, sqlite backend, etc. probably explain the issue between Anki Desktop v2.1.22 and pypi anki v2.1.26.

  2. well closed this discussion on 16 May, 2020 06:23 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac