I want to write an Ubuntu application that helps me deal with a web-based API. I can write it in Python, but I want to know how to build it so that I can execute it as a command on the terminal itself.
Put your Python program in a text file. The first line of that file should be
(I put the "Hello world" line just as an example of Python code). Save it as a text file, for example
Presto, you can now run it:
To be able to access it from any directory and for every user, put it in
Alternatively, you can make a directory called "bin" in your home directory; it will be automatically appended to your PATH variable from through the $HOME/.profile file.
In both of these two last cases to run your script in the terminal, you have to write only:
The extension ".py" is here only for you to indicate that it is a Python script. You can call it "susan" and run it by typing
It will work the same.
Python is a scripting language, which means that you don't have to compile it before running. All you need is getting required version of Python interpreter installed.
For example, you have a python script named foo.py in your home directory, you can run that script with command
The first line in the file should tell it's a python file. First line should be like:
Assuming it's set as executable, if not:
If what you want is to run it without any
If you move foo.py in
As it works fine to put a small python script to
We can then write a small script we put in
Add the variable