Python terminal command?

Discussion in 'Mac Programming' started by lynkynpark86, May 28, 2011.

  1. macrumors 6502

    #1
    I have a finished python script, ready for me to use. Now, is there a way to compile it, or something like that, to use in /bin? Or any other way I can just type "thescript" into terminal, instead of "python /Users/username/Library/myScripts/thescript.py" Ideas?
     
  2. macrumors 603

    Cromulent

    Joined:
    Oct 2, 2006
    Location:
    The Land of Hope and Glory
    #2
    Put:

    Code:
    #!/usr/bin/env python
    on line one of the script (make sure it is the only thing on the line) and add the script to your path (don't put it in /bin though, that is a system directory use /usr/local/bin instead).
     
  3. macrumors 6502a

    Joined:
    Jan 15, 2007
    #3
    also remember to do a
    Code:
    chmod +x your_file_name
    and if you do put it in /usr/local/bin or wherever, I would make sure root owns it:

    sudo chown root:wheel /usr/local/bin/your_file_name
    sudo chmod 755 !$
     

Share This Page