How to execute python scripts with a custom name without .py extension
<p>Lets say I have a python script that makes an http request and prints the response code to the screen and exits.</p>

<pre><code># check_app_status.py

import requests

r = requests.get("https://someapp.com")

print r.status_code
</code></pre>

<p>Now i can run it by </p>

<pre><code>$ python check_app_status.py
200
</code></pre>

<p>What do I need to set up to be able to run it like this </p>

<pre><code>$ check-app
200
</code></pre>

<p>Assuming you're on a unixoid system, you just need to add a shebang line:</p>

<pre><code>#!/usr/local/bin/python

import requests
...
</code></pre>

<p>The exact location of the python executable may vary, so you can alternatively also use the shebang line <code>#!/usr/bin/env python</code>, which should always work.</p>

<p>Then, set the executable bit (<code>chmod +x check-app</code>). Finally, if you want to be able to call it from any location, put it somewhere in your $PATH. I would recommend extending your <code>$PATH</code> with a custom directory where you put your scripts (in this case <code>~/bin</code>). To do that, put this in your <code>.bashrc</code> (or similar):</p>

<p><code>export PATH=$PATH:$HOME/bin</code></p>

python