I ran into a weird problem on my work computer. I installed python via macports but sudo which python results in system python (/usr/bin/python) instead of the macports python (/opt/local/bin/python). Normal which python shows me the macports installed one. What’s going on?

Turns out when you use sudo there is a feature called secure path. If set, it will always override your local path. I checked /etc/sudoers and sure enough, my workplace sets the secure path. Furthermore any attempts to remove it get overwritten every time configs are resynced.

Some potential solutions:

  1. Symlink the binaries you want to use into one of the paths that are in secure path.
  2. Just call explicit binary locations.