2

Say, I have a python script named hello.py, which I run on mac as:

$ python hello.py 

What do I need to do to run it as:

$ hello 
aliteralmind
20.2k17 gold badges80 silver badges109 bronze badges
asked Sep 18, 2015 at 16:22
2

2 Answers 2

9

Add a "shebang" to the top of the file to tell it how to run your script.

#!/usr/bin/env python

Then you need to mark the script as "executable":

chmod +x hello.py

Then you can just run it as ./hello.py instead of python hello.py.

To run it as just hello, you can rename the file from hello.py to hello and then copy it into a folder in your $PATH.

answered Sep 18, 2015 at 16:32
Sign up to request clarification or add additional context in comments.

Comments

1
  1. add the following line at the beginning of the script:

#!/usr/bin/env python

  1. rename hello.py to hello

  2. change the script to be executable: chmod 755 hello

answered Sep 18, 2015 at 16:34

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.