`which python` points to the python I want, but `python` runs the wrong version

I want to use python24 provided by ports, so I've installed it, and python_select -s shows that the version I want is indeed selected. Running which python gives /opt/local/bin/python, and running /opt/local/bin/python gives me the version I want. However when I run python from the shell, I get the /usr/bin/python version instead. I don't have a python alias.

Here's the situation in a nutshell:

  1. I believe the path is set up sensibly, and which python seems to confirm this.
  2. alias only returns 1 entry, which is something unrelated to this.

Nevertheless, running python from the bash shell gives me the wrong python!

I'm kind of stumped! What am I overlooking?


Try hash -d python. This will tell bash to forget where it last saw the python executable.


Perhaps you just updated something and your bash instance has stale information about executables. Try exec bash.

When I:

  1. Start qqq (/usr/bin/qqq) from bash.
  2. Add something qqq to /usr/local/bin/.
  3. Try to start qqq again in the same bash.

It uses the already-looked-up version (/usr/bin/qqq)

However when I restart the bash, it looks for qqq again and gets /usr/local/bin/qqq.