"which python" as a python command?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • chardish@gmail.com

    "which python" as a python command?

    Hello,

    I'm trying to find out in a script where the location of the current
    python is. (I'm writing an installer script in python for a simple
    server application, so i'm going to do a find-replace in a bunch of
    files to give them the absolute path of the python binary.

    One thought might be to use the subprocess module, run "which python"
    as a subprocess, and then peek at stdout, but that seems way too
    complicated. Is there a simple solution for this in just a few lines
    of code?

    Cheers,
    Evan
  • Carsten Haese

    #2
    Re: "which python" as a python command?

    chardish@gmail. com wrote:
    Hello,
    >
    I'm trying to find out in a script where the location of the current
    python is.
    import sys
    print sys.executable

    HTH,

    --
    Carsten Haese

    Comment

    • chardish@gmail.com

      #3
      Re: "which python" as a python command?

      On Sep 25, 11:14 am, Carsten Haese <carsten.ha...@ gmail.comwrote:
      import sys
      print sys.executable
      This is exactly what I needed. Thanks!

      Comment

      Working...