"shebang / usr / bin / env python" causing the wrong python interpreter

What's going on here ?!

$ /usr/bin/env which python /home/dbanas/.local/bin/python $ /home/dbanas/.local/bin/python -V Python 2.7.3 -- EPD_free 7.3-2 (64-bit) $ /usr/bin/env python -V Python 2.4.3 

I stumbled upon this while trying to debug one of my Python scripts that uses

#! /usr/bin/env python

First line. And I do not understand how this is possible.

Thanks! -db

I just noticed that '~ / .local / bin / python' is a link, not an executable. Does this damage the stream '/ usr / bin / env ...'?

Perhaps this is a more concise way of expressing a fundamental riddle ?:

 $ env python -V Python 2.4.3 $ python -V Python 2.7.3 -- EPD_free 7.3-2 (64-bit) 

He just keeps getting funny things and funny things:

 $ which python /home/dbanas/.local/bin/python $ python -c 'import sys; print sys.executable' /usr/bin/python 
+6
source share
2 answers

Most likely what is happening, you do not have the PATH variable exported to the environment. In this case, /usr/bin/env will not have the PATH set, and calling execvp will look for a small set of default directories (usually /usr/bin ).

To see this (in bash ):

 $ export PATH $ declare -p PATH # verify PATH is exported, denoted by the -x declare -x PATH="<my usual path, omitted...>" $ /usr/bin/env python -V # shows my own python build Python 2.7.6 $ export -n PATH # un-export PATH $ declare -p PATH declare -- PATH="<my usual path, omitted...>" $ /usr/bin/env python -V # shows the system (/usr/bin/python) version Python 2.6.6 

So, in short, make sure that export PATH somewhere in your shell files.

+4
source

python seems alias in your shell. Unalias it

 unalias python 

and try again.

0
source

All Articles