This is done differently in Unix-like systems and in Windows. Unix-like is easier.
Unix-like
There are four things you need to do:
- Rename your script to
hello. (It will also work if you keep it as hello.py, but then you'll be calling it as hello.py --message "Hi my name is Tony").
- Give it permission to execute:
chmod 755 hello.
- Add to it a "shebang line". The shebang line is a line that is the first of the script and starts with
#!. This is not a Python feature but a Unix shell feature. For Python, this is just a comment. But the Unix shell looks into that line in order to determine what program it should use to run the file. Nowadays the safest shebang line for Python programs seems to be #!/usr/bin/env python3 because some systems by default don't have a "python" executable, they only have a "python3" executable.
- Put the file in a directory that is included in your "shell path". The shell path is the list of directories in which the shell looks for executable files. Run
echo $PATH to see that list of directories (they are separated by colons). For example, when you type ls, the shell will search that list of directories, in order, until it finds an executable file with the name ls. In that particular example, it will usually find it in the /bin directory. For beginners, putting hello in /usr/local/bin is the best option in many Unix-like systems, like most GNU/Linux systems; that directory is for executable files added to the system through any way other than the system's package manager. For some Unix-like systems like Mac OS X, the appropriate directory might be different.
Beyond the beginner stage, you will want to use virtualenvs, and virtualenv demystified would be a good thing to read after this answer.
Windows
Windows does not provide an easy solution out of the box, so you need to use third-party solutions like pyinstaller, which create an .exe file, that typically contains a copy of the Python interpreter.
There is also a simpler solution. You can create a hello.bat file that executes your program. Assuming python.exe is in C:\Program Files\Python and that hello.py is in C:\Users\Alice, the contents of the file should be:
"C:\Program Files\Python\python.exe" "C:\Users\Alice\hello.py" %*
You can then put hello.bat in a directory that is in the system path, such as C:\Windows. Users don't need to type the whole hello.bat; like .exe files, you can omit the extension and just type hello.
The %* represents the arguments given to hello.bat, so if the user types in hello --message "Hi, I'm Tony", then the batch file will execute C:\...\python.exe C:\...\hello.py --message "Hi, I'm Tony".
PIP
Assuming that you already know how to create a package in PyPI, which is a whole another story, you can use the entry_points argument of setuptools.setup() to do what you want. (Again, I don't think it's easy to make that work in Windows.)
hello, nothello.py) in a directory that is on your search path. This is operating-system dependent and not really a programming question.pyinstaller hello.pyand it created some files and folders. I renamed the hello.py to 'hello'. But after I ranhello --message "Hii", It gave me an error stating that: bash: hello: command not found