How to make a python program run just by typing the name alone at the terminal?
<p>I am not sure what I am supposed to be searching, because everything I have been trying to look up has not really given me the answers that I need.</p>

<p>If anyone can point me in the right direction of exactly what I should be looking at, I would greatly appreciate it. Basically, I want to know the best way to go about making a python program which I can distribute (not publicly). </p>

<p>Once someone has the file they run a script, or run the make command, and the result of this would be that the user can invoke the program from within any directory on the computer by just typing the name (and passing args) in the terminal. </p>

<p>I only know of one way to do this, which I believe is the wrong way. My idea was something as follows:</p>

<p>1.) A main folder, let's call it Ghoul. It would contain 3 files:</p>

<blockquote>
<pre><code>setup.sh
ghoul.sh
ghoul.py
</code></pre>
</blockquote>

<p>2.) The user would have to run setup.sh, which would make ghoul.sh an executable and it would change the name to ghoul and then I would move it to /bin</p>

<p>3.) Within the ghoul file which is now in /bin, the file itself would contain "python /home/user/Ghoul/ghoul.py $@" And this would allow the program to run from any directory just by typing "ghoul"</p>

<p>I hope it's clear what I am trying to accomplish, I know this can't be the appropriate way of doing this. What should I be looking up and reading on to accomplish this? I would like to know how I can do this on Ubuntu and if also ..Windows. </p>

<p>I am also interested if I can limit the "ghoul" command to work only in the Ghoul directory, but of course in any directory that is within the Ghoul directory instead of from within any directory on the system.</p>

<p>Thank you.</p>

<p>On Unix like systems</p>

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

<p>in the very first line of your chmod +x script file will make it executable from the current directory using ./filename</p>

<p>If you want completely straightforward execution from anywhere you can put it on the path somewhere however you choose. </p>

<p>On windows its more complicated, if you want commandline execution the default install should give you the ability to execute </p>

<pre><code>myscript.py
</code></pre>

<p>If its in your path. to drop the .py you need to get .py into the PATHEXT variable. Alternatively if it neds to be distributed to someone without any python install check out www.py2exe.org</p>

python linux bash shell scripting