I am using os.environ to include a path using
os.environ['PATH'] = os.pathsep bin_path
In the bin_path, there is a executable ping. However, doing a shutil.which(ping) shows that ping has been picked up from a different location. How to enforce that ping accessed is the one from bin_path?
CodePudding user response:
PATH is searched in order. If you want your directory to take precedence, you need to put it at the beginning, not the end.
os.environ['PATH'] = bin_path os.pathsep os.environ['PATH']
