This project is archived, but feel free to look around! :)
Reading and editing Windows PATH variables and ensuring python finds your DLLs.
✅ Ensuring that a folder exists in Path.
🔗 Ensuring that DLL(s) are found by python.
🧽 Cleaning the PATH (duplicates, removed folders, sorting)
✏️ Adding or removing folders to/from Path (temporary or permanently)
pip install pathtub
from pathtub import ensure
folder_to_add = r'C:\something to add to path\folder'
# 1) Check Process PATH
# 2) Add to Process PATH if not found
# 3) Add also to User PATH (permanent), if 2) happens
ensure(folder_to_add, permanent=True)ensure(folder) checks if folder is in Process PATH
- If
folderis in Process PATH, does nothing - If
folderis not in Process PATH, adds it to Process PATH - If
folderis not in Process PATH andpermanent=True, adds also to the User PATH or System PATH, depending on thepermanent_mode.
ensure_dll instead.
ensure_dll()is for making sure that python finds needed DLL's (and the DLL's find their dependencies, if any.)- If folder is not yet added, it adds folder to Process PATH and, in case of Python 3.8+, also uses the os.add_dll_directory (More info). If folder is already added, does nothing.
from pathtub import ensure_dll
dll_folder = r'C:\path to\libusb-1.0.21\MS32\dll'
ensure_dll(dll_folder)- Folders added with
ensure_dllcan be removed withforget_dllin the same process. - More info related to
ensure_dllhere.
from pathtub import clean
# Default parameter values shown
clean(sort=True, remove_non_existent=True, remove_user_duplicates=True)- Removes duplicates and empty entries (
;;) from the "User PATH" and "System PATH" (trailing backslash neglected when comparing two folders). Editing "System PATH" needs that python is executed with Admin rights. - Sorts PATH(s) alphabetically (optional, enabled by default). Controlled with the
sortparameter. - Removes folders from PATH(s) that do not exist on the filesystem (optional, enabled by default). Controlled with the
remove_non_existent-parameter. - Removing from "User PATH" the entries that are in the "System PATH" (optional, enabled by default). Controlled with the
remove_user_duplicates-parameter.
- For more detailed example, see Full example of pathtub.clean
- Full documentation of
clean()is in the source code (pathtools.py).
Did not find what you were looking for? See the Rest of the docs.
