The .py at the end is not required - the file name makes no difference to how executable it is. However, the .py does serve as a hint to text editors that do syntax highlighting, so you may choose to only change the flename after you have it working.
To be executable as a command, two things need to happen. Firstly, the first line of the file must be:
which tells the OS which interpreter to use to run the file.
Secondly, the file must be marked as executable. You can do this in a file manager by right-clicking the file and editing its properties, or you can use the chmod command, e.g.
Code:
chmod +x myprogram.py
Now you can run it as a command. e.g.
You may wish to place a copy in somewhere that is in your search path, so that you don't have to give the full path to the file every time you use it. The best place to put it is probably in /usr/local/bin - you need to be root to write into that directory, so use a command like this (the command below renames the file as it copies it to remove the ".py":
Code:
sudo cp myprogram.py /usr/local/bin/myprogram
Bookmarks