Workaround for binaries on Windows failing: module 'nt' has no attribute '_path_splitroot'

For the dudes who cannot use your application built with setuptools, face this error:

  File "__main__", line 3, in <module>
  File "importlib._bootstrap", line 1042, in _handle_fromlist
  File "importlib._bootstrap", line 219, in _call_with_frames_removed
  File "importlib._bootstrap", line 991, in _find_and_load
  File "importlib._bootstrap", line 975, in _find_and_load_unlocked
  File "importlib._bootstrap", line 671, in _load_unlocked
  File "importlib._bootstrap", line 827, in exec_module
  File "direct.directbase.DirectStart", line 24, in <module>
  File "direct.showbase.ShowBase", line 179, in __init__
  File "direct.showbase.ShowBase", line 546, in __setupProfile
  File "importlib", line 127, in import_module
  File "importlib._bootstrap", line 1014, in _gcd_import
  File "importlib._bootstrap", line 991, in _find_and_load
  File "importlib._bootstrap", line 971, in _find_and_load_unlocked
  File "importlib._bootstrap", line 914, in _find_spec
  File "importlib._bootstrap_external", line 1407, in find_spec
  File "importlib._bootstrap_external", line 1376, in _get_spec
  File "importlib._bootstrap_external", line 1348, in _path_importer_cache
  File "importlib._bootstrap_external", line 1324, in _path_hooks
  File "importlib._bootstrap_external", line 1594, in path_hook_for_FileFinder
  File "importlib._bootstrap_external", line 1469, in __init__
  File "importlib._bootstrap_external", line 171, in _path_isabs
AttributeError: module 'nt' has no attribute '_path_splitroot'

I found a workaround - By creating the method ourselves:

# ADD THIS AT THE BEGINNING OF THE FILE, OR BEFORE YOU CALL PANDA3D OR DIRECT

def _path_splitroot(path):
    if path[1] == ':':
        split = (path[:3], path[3:])
    else:
        split = ('', path)  
        
    return split

import nt

nt._path_splitroot = _path_splitroot

This works on my interpreter - Python 3.8.10 on Windows 10.

1 Like