Fatal error detected: Failed to execute script runanki

I updated my Windows yesterday and upgraded to v2.1.44 today. Since the upgrade, Anki won’t start and I’m getting this error.

I executed “cd \program files\anki & anki-console”, and here is the output.

[19640] PyInstaller Bootloader 3.x
[19640] LOADER: executable is C:\Program Files\Anki\anki-console.exe
[19640] LOADER: homepath is C:\Program Files\Anki
[19640] LOADER: MEIPASS2 is NULL
[19640] LOADER: archivename is C:\Program Files\Anki\anki-console.exe
[19640] LOADER: C:\Program Files\Anki\anki-console.exe contains a digital signature
[19640] LOADER: No need to extract files to run; setting extractionpath to homepath
[19640] LOADER: SetDllDirectory(C:\Program Files\Anki)
[19640] LOADER: Already in the child - running user’s code.
[19640] LOADER: Python library: C:\Program Files\Anki\python38.dll
[19640] LOADER: Loaded functions from Python library.
[19640] LOADER: Manipulating environment (sys.path, sys.prefix)
[19640] LOADER: sys.prefix is C:\Program Files\Anki
[19640] LOADER: Pre-init sys.path is C:\Program Files\Anki\base_library.zip;C:\Program Files\Anki
[19640] LOADER: Setting runtime options
[19640] LOADER: Initializing python
[19640] LOADER: Overriding Python’s sys.path
[19640] LOADER: Post-init sys.path is C:\Program Files\Anki\base_library.zip;C:\Program Files\Anki
[19640] LOADER: Setting sys.argv
[19640] LOADER: setting sys.MEIPASS
[19640] LOADER: importing modules from CArchive
[19640] LOADER: extracted struct
[19640] LOADER: callfunction returned…
[19640] LOADER: extracted pyimod01_os_path
[19640] LOADER: callfunction returned…
[19640] LOADER: extracted pyimod02_archive
[19640] LOADER: callfunction returned…
[19640] LOADER: extracted pyimod03_importers
[19640] LOADER: callfunction returned…
[19640] LOADER: Installing PYZ archive with Python modules.
[19640] LOADER: PYZ archive: PYZ-00.pyz
[19640] LOADER: Running pyiboot01_bootstrap.py
[19640] LOADER: Running pyi_rth_win32comgenpy.py
[19640] LOADER: Running pyi_rth_multiprocessing.py
[19640] LOADER: Running pyi_rth_certifi.py
[19640] LOADER: Running pyi_rth_pyqt5.py
[19640] LOADER: Running pyi_rth_pkgres.py
[19640] LOADER: Running pyi_rth_pyqt5webengine.py
[19640] LOADER: Running runanki.py
Traceback (most recent call last):
File “runanki.py”, line 3, in
File “C:\release\lib\site-packages\pyinstaller-4.0.dev0-py3.8.egg\PyInstaller\loader\pyimod03_importers.py”, line 497, in exec_module
File "aqt_init
.py", line 245, in
File "aqt_init
.py", line 252, in AnkiApp
File “getpass.py”, line 168, in getuser
ModuleNotFoundError: No module named ‘pwd’
[19640] Failed to execute script runanki
[19640] LOADER: OK.
[19640] LOADER: Manually flushing stdout and stderr
[19640] LOADER: Cleaning up Python interpreter.

Additional information:
The Anki shortcut anki.exe, which is in C:\Program Files\Anki, launches fine if double-clicked on in the folder itself. Any shortcut, however, doesn’t work and gives this error.

ModuleNotFoundError: No module named ‘pwd’

It appears it happens if USERNAME environment variable, as in C:\Users\%USERNAME%, isn’t set on Windows. At least, the same error message can be seen after starting Anki with set "USERNAME=" & anki-console.exe

If anyone is struggling with this, here is a workaround:

Since pwd is only availble on Unix, Python tries to guess the current user’s username from the following environment variables:

* LOGNAME
* USER
* LNAME
* USERNAME

If for some reason none of these are set on your windows machine (it was my case when running tests on a build machine), find some way to define one of these variables in order to prevent python to try to import pwd.

https://github.com/gitpython-developers/GitPython/issues/356#issuecomment-345004125

def getuser():

This works on Windows as long as USERNAME is set.

https://github.com/python/cpython/blob/a9e20cf7bbf3ba39260fca112938f95e4f317efc/Lib/getpass.py#L158

It’s not clear what happened and how to fix it, because USERNAME should be set by Windows automatically, maybe on log in, and could be found with regedit at HKEY_CURRENT_USER\Volatile Environment

It probably won’t exist.

Maybe it could be fixed by changing your current username to something different, maybe temporarily, either with

  • netplwiz

https://social.technet.microsoft.com/Forums/en-US/cd35f292-616a-4622-96cb-19138a59d7e8/changing-username-variable?forum=win10itprogeneral

  • lusrmgr.msc

As the last possible option, maybe add USERNAME with regedit to HKEY_CURRENT_USER\Volatile Environment (it’ll be mirrored to Computer\HKEY_USERS\<USER_SID>\Volatile Environment) or as User environment variable.

3 Likes

Users who’ve hit this in the past reported that the problem went away after they installed all Windows updates and restarted a few times.

1 Like