lervag/apy

Error: No module named 'anki' when running 'apy'

pietro14 opened this issue · 4 comments

I am trying to run apy on my laptop with Linux Mint 21:

Kernel: 5.15.0-56-generic x86_64
Desktop: Cinnamon 5.4.12
Distro: Linux Mint 21 Vanessa (base: Ubuntu 22.04 jammy )

When I run apy info I get the following error:

Traceback (most recent call last):
  File "/home/pietro/.local/bin/apy", line 33, in <module>
    sys.exit(load_entry_point('apy', 'console_scripts', 'apy')())
  File "/home/pietro/.local/bin/apy", line 25, in importlib_load_entry_point
    return next(matches).load()
  File "/usr/lib/python3.10/importlib/metadata/__init__.py", line 171, in load
    module = import_module(match.group('module'))
  File "/usr/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/home/pietro/git/apy/apy/cli.py", line 8, in <module>
    from apy.anki import Anki
  File "/home/pietro/git/apy/apy/anki.py", line 7, in <module>
    import anki
ModuleNotFoundError: No module named 'anki'

This is what I have done before trying running apy:

  1. I installed Anki from the official web site https://apps.ankiweb.net/ (anki-2.1.55-linux-qt6). Anki works well.

  2. I cloned apy repo in $HOME/git/apy

  3. I installed apy with pip install -e .

After getting the error, I searched online and I found this similar issue: #1

Following the solution for the issue #1 I cloned the anki repo (https://github.com/ankitects/anki.git) in $HOME/git/anki

Then I tried the following:

export APY_ANKI_PATH=$HOME/git/anki
apy info

But I still get the same error as above.

Another useful info might be, that I recently changed my laptop. On the previous one, I could use apy without problems (it was really useful!). But I don't remember what I did when I installed it the first time on my old laptop. The only difference is the OS version: on the old one I had Linux Mint 20, on the new one I have Linux Mint 21

Could you help me? Thank you in advance!

  1. I installed apy with pip install -e .

Did you read the README instructions? Specifically, these? I believe it may be as simple as installing aqt with pip install aqt.

You could also try the "Other" approach. If you use a virtual environment, it should be quite safe to try installing without messing with your user or root environments.

Notice, though, it may be useful to specify the version of aqt to be the same as the version you've used for the regular Anki install.

Following the solution for the issue #1 I cloned the anki repo (https://github.com/ankitects/anki.git) in $HOME/git/anki

Then I tried the following:

export APY_ANKI_PATH=$HOME/git/anki
apy info

I would have expected that to work, but it clearly doesn't. In any case, I think you should start by following the suggestions in the README.

Thanks! Indeed, I didn't read that part... sorry. After installing aqt I don't get that error anymore.

By the way, I now get another error when running apy info:

Config file:             Not found
Base path is not properly set!
Aborted!

In fact, there is no config file for apy in: ~/.config/apy/

Should I open another issue for that?

Should I open another issue for that?

No, that's OK; we'll figure things out here. :)

Thanks! Indeed, I didn't read that part... sorry. After installing aqt I don't get that error anymore.

Good. Then we are close!

By the way, I now get another error when running apy info:

Config file:             Not found
Base path is not properly set!
Aborted!

In fact, there is no config file for apy in: ~/.config/apy/

This is explained here: https://github.com/lervag/apy/blob/59d6b50301e647099545ede97ae778fccb9738d3/README.md#configuration

The point is that apy needs to know where your Anki database is. The base path is therefore required. It should be specified either with the -b option on the command line or in apy.json with the base key. You can also use environment variables ($APY_BASE or $ANKI_BASE).

Fascinatingly, someone suggested changes that will provide some common defaults for the base directory, which means you may not need to apply any config to make things work: #51.