dccsillag
dccsillag

Reputation: 957

How Can I Execute A Python Script By Just Typing The Script's Name?

I have a python script that I want to execute from the terminal, but I don't want to use the command pythonscriptName.py, instead, I'd like to just type scriptName. Is that possible? If it is, how?

I had a look in here and here, but it doesn't work (probably because I'm on a different os).

I'm using python 2.7.9 on osx Yosemite (10.10.3).

Upvotes: 2

Views: 3805

Answers (1)

cfh
cfh

Reputation: 4666

Put this as the first line in your Python script:

#!/usr/bin/python

(or wherever your Python interpreter lives).

Then give the script the executable bit:

chmod +x scriptName.py

Now you should be able to execute it like ./scriptName.py. You can then put a symlink without the .py extension somewhere in your path.

Upvotes: 5

Related Questions