0

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 ?

  • How is the app started? – Mark Apr 2 '14 at 12:04
  • @Mark From the commandline using the command I listed above: python2.7 script where script can be any python script. (Actually the same problem exist if I just start the python interpreter using python2.7) – Zitrax Apr 2 '14 at 12:15
1

Is that what you want ?

>>> import sys
>>> sys.executable
/System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python
  • Thanks, this helps. I was hoping there was some non python specific solution though for going from an executable to the correct full absolute path. But your answer will probably solve my immediate issue. – Zitrax Apr 2 '14 at 12:26
  • I came across the same "problem" few days back on another question : apple.stackexchange.com/questions/125825/… I still didn't find what exactly happens. – Matthieu Riegler Apr 2 '14 at 12:29
  • @MatthieuRiegler no you issue is different - yours is a simple one of which is the first executable on the path - this is more complex as there is something internal to python – Mark Apr 2 '14 at 14:19
  • I was talking about the "funny part", a the bottom of my answer. – Matthieu Riegler Apr 2 '14 at 14:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .