Full path to python as reported by ps

bashpathpython

When I run python from the shell I for example do python2.7 script.

I later need to find this command again based on the ps aux output, however this output shows a full absolute path like this:

/System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python

I am unsure how I can resolve python2.7 to the path above. I tried to install realpath (brew install coreutils), and ran realpath `which python2.7`, however that is not giving the exact same path, it gives:

/System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7

I also tried python -c "import os; print os.path.realpath('/usr/bin/python2.7')" but that gives the same different path.

Why the difference and is there any way I can resolve to the other path ?

Best Answer

Is that what you want ?

>>> import sys
>>> sys.executable
/System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python