This question already has an answer here:

I'm on OSX and if I run python --version in a bash shell, I get this:

$ python --version
Python 3.7.3

But the which python command appears to be pointing to version 2.7.

$ which python
/usr/local/bin/python ls -al /usr/local/bin/python
lrwxr-xr-x  1 me  admin  36 11 Apr 22:28 /usr/local/bin/python -> ../Cellar/python@2/2.7.16/bin/python

I think this is because I have done alias python=python3: but why does which python not pick up the alias?

marked as duplicate by muru, Mr Shunz, teppic, Fabby, Prvt_Yadv Apr 20 at 7:31

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 2
    … which points out that the premise of this question is faulty, because sometimes it does. unix.stackexchange.com/q/10525/5132 – JdeBP Apr 18 at 12:26
  • The type command may be of interest to you... – ivanivan Apr 18 at 13:12
  • @JdeBP have edited title. – Richard Apr 18 at 13:38

GNU which - is a utility that is used to find which executable (or alias or shell function) is executed when entered on the shell prompt.

Stolen from the which(1) man page:

The recommended way to use this utility is by adding an alias (C shell) or shell function (Bourne shell) for which like the following:

which () {
  (alias; declare -f) | /usr/bin/which --tty-only --read-alias --read-functions --show-tilde --show-dot $@
export -f which

Put this in your ~/.bashrc or whatever shell you use to enable this permanently.

Not the answer you're looking for? Browse other questions tagged or ask your own question.