1. In MiKTeX, check Settings → Always in “You can choose whether missing packages are to be installed automatically (on-the-fly).”

  2. Adjust Anki’s LaTeX Build Process

    • Download Anki add-on: Edit LaTeX build process.
    • Adjust build process in Anki (Tools → Add-ons → select 'Edit LaTeX build process' → Config).

Check this tutorial for extra details.