Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't load media in Anki 2.1.35

See original GitHub issue

When creating a new deck with a set of new cards, running the line my_package.media_files = media_list, and importing the .apkg file to Anki the media names do appear in the cards fields, but neither the images are shown or the sound is being played, which seems to indicate that my_package.media_files is not doing its job (here is a sample code that supposedly should work that I also tried:

It took me a while to realize why my new Anki decks could not show the media files that I wanted to, until I ended up changing my_package.media_files = media_list with the following function, where media_path is the folder where Anki stores all the media (C:\Users\user\AppData\Roaming\Anki2\User 1\

def move_media(media_list, media_path): for file in media_list: ...destination = media_path + '\\' + os.path.basename(file) ...shutil.move(file, destination)

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

kerrickstaleycommented, Jan 21, 2021

Thanks for the help @remiberthoz !!

woodsonchilduniversecommented, Jan 17, 2021

Environment : Python 3.6.6 genanki 0.10 (I used pip to update it today) Windows Problem : image cannot show on the anki The apkg file:1the picture are in the file 2the media which I open in notebook is right.And I post its context below. {“0”: “21.png”, “1”: “1.png”, “2”: “2.png”, “3”: “3.png”, “4”: “4.png”, “5”: “5.png”, “6”: “6.png”, “7”: “7.png”, “8”: “8.png”, “9”: “9.png”, “10”: “10.png”, “11”: “11.png”, “12”: “12.png”, “13”: “13.png”, “14”: “14.png”, “15”: “15.png”, “16”: “16.png”, “17”: “17.png”, “18”: “18.png”, “19”: “19.png”, “20”: “20.png”} My code is below.

pictureList =['D:\\Desktop\\xyz\\word\\media\\21.png', 'D:\\Desktop\\xyz\\word\\media\\1.png', 'D:\\Desktop\\xyz\\word\\media\\2.png', 'D:\\Desktop\\xyz\\word\\media\\3.png', 'D:\\Desktop\\xyz\\word\\media\\4.png', 'D:\\Desktop\\xyz\\word\\media\\5.png', 'D:\\Desktop\\xyz\\word\\media\\6.png', 'D:\\Desktop\\xyz\\word\\media\\7.png', 'D:\\Desktop\\xyz\\word\\media\\8.png', 'D:\\Desktop\\xyz\\word\\media\\9.png', 'D:\\Desktop\\xyz\\word\\media\\10.png', 'D:\\Desktop\\xyz\\word\\media\\11.png', 'D:\\Desktop\\xyz\\word\\media\\12.png', 'D:\\Desktop\\xyz\\word\\media\\13.png', 'D:\\Desktop\\xyz\\word\\media\\14.png', 'D:\\Desktop\\xyz\\word\\media\\15.png', 'D:\\Desktop\\xyz\\word\\media\\16.png', 'D:\\Desktop\\xyz\\word\\media\\17.png', 'D:\\Desktop\\xyz\\word\\media\\18.png', 'D:\\Desktop\\xyz\\word\\media\\19.png', 'D:\\Desktop\\xyz\\word\\media\\20.png']

def makeApkg(List):
    #Using a list to generate a apkg.file
    my_model = genanki.Model(
    'Simple Model with Media',
    {'name': 'Question'},
    {'name': 'Answer'},
    {'name': 'MyMedia'},
    {'name': 'MyAnswerMedia'}     	# ADD THIS
    'name': 'Card 1',
    'qfmt': '{{Question}}<br>{{MyMedia}}',              # AND THIS
    'afmt': '{{FrontSide}}<hr id="answer">{{MyAnswerMedia}}<br>{{Answer}}',
    deckname = "newDecks"
    decknumber = 98765675
    my_deck = genanki.Deck(
    mediaFile = r"D:\Desktop\xyz\word\media"
    #The pictures are in this file.
    imageList = []
    #anki media files

    MyMedia = ""
    MyAnswerMedia = ""

    for picture in List:
        MyMedia += '<img src = ' + '"' + os.path.basename(picture) + '"' + '/>'
        MyAnswerMedia += '<br>'+ '<img src = ' + '"' + os.path.basename(picture) + '"' + '/>'
        question = "sdfg"
        answer = "kjhgh"
        # two randon strings
        fields=[question, answer, MyMedia, MyAnswerMedia])

    my_package = genanki.Package(my_deck)
    my_package.media_files = imageList
    my_package.write_to_file(deckname + r".apkg")

Here is my apkg file.I rename it to upload.

By the way thanks for your article and your package,Both help me greatly.It is really a fantastic article.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Anki 2.1.35 Changelog - Reddit
Just chiming in to say I'm getting the same error. Can't downgrade to an older version and the partial install broke my existing...
Read more >
Neurofunk - Anki Forums
One possible option is to install Anki 2.1.35-alternate and use this Anki version or replace mpv.exe in C:\Program Files\Anki with ...
Read more >
About Anki Features
Media -Rich. Embed audio clips, images, videos and scientific markup on your cards, with precise control over how it's shown. Optimized. Anki will...
Read more >
Releases · ankitects/anki - GitHub
Fixed an error that occurred after a one-way download fetched a collection with a different scheduler version enabled. Fixed desktop hanging when attempting...
Read more >
The 5 MUST-HAVE Add Ons for ANYONE Using Anki!
Here are the top 5 Anki Add Ons I recommend for ALL students (regardless of whether or not you are ... Your browser...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found