[Bug] Anki running in Python Virtual Environment doesn't display images

I have installed Anki (Version ⁨2.1.54 (b6a7760c)⁩ Python 3.9.2 Qt 5.15.2 PyQt 5.15.2) on Linux using the aqt pip library as per https://betas.ankiweb.net/#via-pypipip, and all is functioning except images (though I have not tested audio files).

The images display as the blue image icon, but the images work on non-python Anki instances as well as on the mobile apps.

The images don’t load anywhere in Anki, including the preview, browse, editor, and main Anki card viewer.

The files are fine in the collection.media folder and open without errors, but they do not display in this Anki installation, even when changing the img scr to an absolute path.

When opening Help>About from the main menu, the Anki logo image renders correctly, so I am unsure of the cause of the problem.

Steps to reproduce: install Anki as per the guide linked above, open a card which has an image in it.

Works for me. Perhaps you’re missing an image library - running with QT_DEBUG_PLUGINS=1 may reveal something.

I’ve set the environment variable in my Anki binary folder but get no extra output from the terminal in comparison to without it. Is there something else I could try?

I’m not sure what you mean by that. Did you try the following in a terminal? You should see output.

export QT_DEBUG_PLUGINS=1
anki

I’ve managed to make a few observations using the debug info (I had forgotten to write export and instead just ran QT_DEBUG_PLUGINS=1 in the terminal!).

Firstly, changing the name of the image in the deck browser editor to another name returns a Not found: in the terminal, but this does not happen when the original name is inputted, meaning that Anki can find the file.

Secondly, I used the code from github: ankitects/anki/blob/main/qt/aqt/about.py to find the path of the working image in the About pop-up, and to my amazement it (/_anki/imgs/anki-logo-thin.png) worked!

I then thought perhaps the permissions were set up incorrectly but the files in the collection.media and the site-packages/aqt/data/web/imgs folder had the same permissions. I copied the anki-logo-thin.png file over to the collection.media folder where the images on my cards were, put the name into the editor, but the image did not load, despite not returing a Not found: error.

Perhaps this has something to do with the collection.media.db2 database? I tried reading it but there are a lot of non-ASCII characters with the names of my image files between them. I have rebuilt the database using the menu option in Anki but this doesn’t change anything.

Copying the image I want to include in my card to /anki-venv/lib/python3.9/site-packages/aqt/data/web/imgs/my_image_here.jpg and changing the path of the image in the html to /_anki/imgs/my_image_here.jpg displays the image. However, this is a tacky workaround which would require manual intervention each time an image is put into Anki.

You said you tested Anki in a Python Virtual Environment, was this on Linux? I am running Debian GNU/Linux 11 (bullseye) aarch64.

Images displays in the review screen correctly for me on Debian 11/ARM. Did you try Check Media to confirm your filenames are encoded correctly?

Yes, I have run Check Media.

I find the most puzzling thing that despite being able to verify they exists, it can’t display the images when they’re in the media folder.

Yes, that is strange. Is there non-Latin text in path of your Anki data folder?

/home/admin/.local/share/My-Profile/User/collection.media

is the path to my data folder, but it can also be referenced by

~/.local/share/Anki2/My-Profile/collection.media

Changing my profile name to one without hyphens and even changing the Anki Data Folder location using the -b flag to one without a dot doesn’t yield any different results.

A slight deviation but I have noticed that when opening the collection.media.db2 file with sqlite3 it has names of files which are deleted.

For example a file which is in my cards would be

INSERT INTO media VALUES('image-randomcharacters.jpg','randomcharacters',mtimevalue,0);

whereas one which was deleted can be identified by

INSERT INTO media VALUES('image-randomcharacters.jpg',NULL,0,0);

Is this expected behaviour?

This bug does not occur in Ubuntu on the same system. Which OS were you using? This bug happens for me when I use Raspberry Pi OS.

pi 4 - Qt Quick cross compiled application didn't show images on raspberry pi 4 - Raspberry Pi Stack Exchange seems to be related

Hi! With the help on @jiqz, I got Anki working in the Python virtual environment, but have the same problem. Perhaps it’s related to the Raspberry Pi OS?

I tested with a stock Debian 11. The media database is unlikely to be related to the issue, and deleted files being in it is normal. It sounds like it may be an issue with the Qt version distributed with Raspberry Pi OS.