Osx: Using Bash To Find Python Is Different Than Using /usr/bin/env Python
Solution 1:
Bash keeps a cached lookup table in memory, which you can examine with hash
. If you add a program to your PATH
with the same name as a program you have used before at a different location, bash
will still remember the old location. env
obviously bypasses this cache; or you can remove it with hash -r python
.
Also note that which
is nonportable and often not the correct tool to use; type
is specified by POSIX, and is built-in to any modern shell.
Solution 2:
When you run program from $PATH
( so, like $ python
) then it's argv[0]
is set to just it's name ( eg. python
), not full path. And python 2.7 version of sys.executable
looks at $PATH
if argv[0]
doesn't have backslash on beggining ( so, eg. when you run it like in last example ). And it seems that it's not resolving symlinks, just printing first found path.
As we can see in python's code, on OS X it uses NSGetExecutablePath
to itself in $PATH
. And on Apple's site they say that NSGetExecutablePath
That is, the path may be a symbolic link and not the real file.
Post a Comment for "Osx: Using Bash To Find Python Is Different Than Using /usr/bin/env Python"