diff --git a/espefuse.py b/espefuse.py index 9b8633a228..2222d4e55c 100755 --- a/espefuse.py +++ b/espefuse.py @@ -18,9 +18,12 @@ # Linux/macOS: remove current script directory to avoid importing this file # as a module; we want to import the installed espefuse module instead with contextlib.suppress(ValueError): - if sys.path[0].endswith("/bin"): - sys.path.pop(0) - sys.path.remove(os.path.dirname(sys.executable)) + executable_dir = os.path.dirname(sys.executable) + sys.path = [ + path + for path in sys.path + if not path.endswith(("/bin", "/sbin")) and path != executable_dir + ] # Linux/macOS: delete imported module entry to force Python to load # the module from scratch; this enables importing espefuse module in diff --git a/espsecure.py b/espsecure.py index c58eabf156..29b8e48e83 100755 --- a/espsecure.py +++ b/espsecure.py @@ -18,9 +18,12 @@ # Linux/macOS: remove current script directory to avoid importing this file # as a module; we want to import the installed espsecure module instead with contextlib.suppress(ValueError): - if sys.path[0].endswith("/bin"): - sys.path.pop(0) - sys.path.remove(os.path.dirname(sys.executable)) + executable_dir = os.path.dirname(sys.executable) + sys.path = [ + path + for path in sys.path + if not path.endswith(("/bin", "/sbin")) and path != executable_dir + ] # Linux/macOS: delete imported module entry to force Python to load # the module from scratch; this enables importing espsecure module in diff --git a/esptool.py b/esptool.py index 60e5bd3397..ee3fdc90f7 100755 --- a/esptool.py +++ b/esptool.py @@ -18,9 +18,12 @@ # Linux/macOS: remove current script directory to avoid importing this file # as a module; we want to import the installed esptool module instead with contextlib.suppress(ValueError): - if sys.path[0].endswith("/bin"): - sys.path.pop(0) - sys.path.remove(os.path.dirname(sys.executable)) + executable_dir = os.path.dirname(sys.executable) + sys.path = [ + path + for path in sys.path + if not path.endswith(("/bin", "/sbin")) and path != executable_dir + ] # Linux/macOS: delete imported module entry to force Python to load # the module from scratch; this enables importing esptool module in