Python terminal command?

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

  1. macrumors 6502

    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/" Ideas?
  2. macrumors 603


    Oct 2, 2006
    The Land of Hope and Glory

    #!/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

    Jan 15, 2007
    also remember to do a
    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