Creating an alias for Python in bash/zsh

Solution 1:

From man bash

Aliases  are not expanded when the shell is not interactive, unless the
expand_aliases shell option is set using shopt (see the description  of
shopt under SHELL BUILTIN COMMANDS below).

So unless you explicitly set an option, aliases aren't expanded in scripts and any reference to python will call the binary directly. For interactive use it's probably best to call python2 directly if you rely on pre-3 syntax/functionality.

PS: AFAIK it's the same for zsh.