I am trying to run ipython from the bash (version 4.4.19) command line.
As a Python developer, I have various installations of ipython at various versions in various virtualenvs' paths, and so it is important to know which one I am running. Hence the $PATH is always changed when I change virtualenv, and this would a typical value for PATH:
$ echo $PATH
/Users/jab/.virtualenvs/tools/bin:/Users/jab/bin:/Users/jab/src/git/hub/jab/bin:/usr/local/gnu:/bin:/usr/local/bin:/usr/bin
The important detail in that is that the first entry is "/Users/jab/.virtualenvs/tools/bin", and that the file /Users/jab/.virtualenvs/tools/bin/ipython does exist:
$ ls -l /Users/jab/.virtualenvs/tools/bin/ipython
-rwxr-xr-x 1 jab staff 252 May 11 15:18 /Users/jab/.virtualenvs/tools/bin/ipython
As expected, which says that that file will be run as the "$ ipython" command
$ which ipython
/Users/jab/.virtualenvs/tools/bin/ipython
$ $(which ipython) -c "import sys; print(sys.executable)"
/Users/jab/.virtualenvs/tools/bin/python
However, that is not actually the case, and /usr/local/bin/ipython is run instead
$ ipython -c "import sys; print(sys.executable)"
/usr/local/bin/python3
Can someone explain why bash is ignoring my $PATH and using the "wrong" executable? And what do I need to change (in my bashrc, or on my system (macOS 10.12.3)) so that executables are chosen by bash in the order determined by my $PATH.
Note: This is not a duplicate Bash is not finding a program even though it's on my path, because that asks how PATH works to find any program, whereas this question is anout why the wrong program is found.
(which ipython) -c "import sys; print(sys.executable)"gives/Users/jab/.virtualenvs/tools/bin/python. what doesls -l /Users/jab/.virtualenvs/tools/bin/pythonreturn?python(pip, ...) command runs fine: from thevirtualenv.$ ls -l /Users/jab/.virtualenvs/tools/bin/pythongives-rwxr-xr-x 1 jab staff 42720 Nov 9 2016 /Users/jab/.virtualenvs/tools/bin/python$ (which ipython) -c ...should actually be$ $(which ipython) -c ..., since you need$(...)for command substitution in order to use that. Maybe you should update your question to do that (or just use the full path/Users/jab/.virtualenvs/tools/bin/ipythondirectly, since there's no ambiguity there...)