Disable running self hosted servers via .exe files on Windows

On Windows if a user changes the Python version in the launcher while the self hosted server is still running, the .venv deletion may fail and the launcher and Anki may become unlaunchable.

This issue can be resolved by terminating the server and manually deleting the AnkiProgramFiles directory. (Previous thread about this issue)

But regular users might not realize they need to close the server, or they might not know where AnkiProgramFiles is located. (uninstalling via the launcher might resolve the issue, but I haven’t tried it because I’m worried the data might get deleted.)

So for Windows I think it might be safer to block execution via the .exe file (packaged build) and only allow execution using the anki module (with pip, -m anki.syncserver).

  • If the server is running in a virtual environment or Docker using anki.syncserver, Anki and the server’s venv are not shared, so this issue does not occur.
  • MacOS and Linux can delete the binary during execution so I think this issue may not occur. (I have not checked)
  • This issue does not seem to occur during normal updates or downgrades that do not delete the venv. (Python version is the same)

Reproduction Steps (Windows):

  1. Run the self hosted server using Anki’s exe file. (From a Packaged Build)
    set SYNC_USER1=user:pass
    "\Program Files\anki\anki-console.exe" --syncserver
    
  2. Downgrade from Anki 25.09 to 25.02.7 via the launcher. (change the Python version)
  3. Deleting the .venv fails and preventing the launcher from installing and running Anki.

Error report (Launcher):

  • Failed to delete venv

Anki Launcher

1) Latest Anki (press Enter)

2) Choose a version

3) Keep existing version (25.09.2)

5) Allow betas: on

6) Cache downloads: on

7) Download mirror: off

8) Uninstall

> 2

Checking for updates...

Latest releases: 25.09.2, 25.08b5, 25.07.5, 25.06b7, 25.02.7

Enter the version you want to install:

> 25.02.7

Updating Anki...

Using CPython 3.9.23

error: failed to remove directory `C:\Users\user_name\AppData\Local\AnkiProgramFiles\.venv`: Access is denied. (os error 5)

Install failed: Failed to run (2): C:\Users\user_name\AppData\Local\Programs\Anki\uv.exe sync --upgrade --no-config --managed-python --python 3.9

Error: Failed to run (2): C:\Users\user_name\AppData\Local\Programs\Anki\uv.exe sync --upgrade --no-config --managed-python --python 3.9

Press enter to close...


  • Anki and Launcher cannot run

Anki Launcher

1) Latest Anki (press Enter)

2) Choose a version

3) Allow betas: on

4) Cache downloads: on

5) Download mirror: off

6) Uninstall

>

Checking for updates...

Updating Anki...

error: Querying Python at `C:\Users\user_name\AppData\Local\AnkiProgramFiles\.venv\Scripts\python.exe` failed with exit status exit code: 106

[stderr]

failed to locate pyvenv.cfg: The system cannot find the file specified.

Install failed: Failed to run (2): C:\Users\user_name\AppData\Local\Programs\Anki\uv.exe sync --upgrade --no-config --managed-python --python 3.13.5

Error: Failed to run (2): C:\Users\user_name\AppData\Local\Programs\Anki\uv.exe sync --upgrade --no-config --managed-python --python 3.13.5

Press enter to close...

How common is this? Is it something Anki really need to handle? The sync server is an advanced feature, so I imagine optimizing for edge cases is not a priority.

1 Like

This issue only occurs when Windows users updating (or downgrade) Anki are using a self hosted server so it is not important (I don’t know how many users are using self hosted servers on Windows but probably not many).

Recently Anki has been developing a feature to integrate Python into Anki on Windows, so this issue may occur when implementing that feature. (it may not occur, I haven’t checked yet)

After that Python updates are very rare so I think it probably won’t be relevant for several years (users who downgrade are also very rare). If it occurs I think users will probably mistake it for a launcher bug and report the issue (e.g. after updating Anki, Anki and the launcher stopped working), so handling that might be sufficient.

1 Like