PDA

View Full Version : Python terminal command?




lynkynpark86
May 28, 2011, 09:47 AM
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?



Cromulent
May 28, 2011, 10:32 AM
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?

Put:

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

foidulus
May 28, 2011, 04:28 PM
Put:

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

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 !$