diff --git a/bitsandbytes/cuda_setup/main.py b/bitsandbytes/cuda_setup/main.py index 91f7c10db..34c035425 100644 --- a/bitsandbytes/cuda_setup/main.py +++ b/bitsandbytes/cuda_setup/main.py @@ -197,11 +197,13 @@ def remove_non_existent_dirs(candidate_paths: Set[Path]) -> Set[Path]: try: if path.exists(): existent_directories.add(path) + except PermissionError as pex: + # Handle the PermissionError first as it is a subtype of OSError + # https://docs.python.org/3/library/exceptions.html#exception-hierarchy + pass except OSError as exc: if exc.errno != errno.ENAMETOOLONG: raise exc - except PermissionError as pex: - pass non_existent_directories: Set[Path] = candidate_paths - existent_directories if non_existent_directories: