PDA

View Full Version : make application that can run via terminal command?



baskar007
November 4th, 2009, 11:07 AM
how to make my python application run via application name as its terminal command?

for example:
if i type google-chrome on terminal it will open chrome browser.

0cton
November 4th, 2009, 02:54 PM
give it executable privileges (chmod +x ) (logically)
don't forget about the shebang (#! /usr/bin/env python at first line)
and copy it to /usr/bin/ (you need root to be able to do it)

A_Fiachra
November 4th, 2009, 03:01 PM
Don't do that!



Keep a local directory of python programs.

chmod 750 <myprog.py>
./myprog.py

If you clutter the /usr/bin directory with your own executables, you will end up screwing yourself.

The idea is you run your stuff from under your home directory, do not include '.' in your PATH, don't copy executables to a directory in your PATH -- unless you really know what you are doing, and you don't yet.

ve4cib
November 4th, 2009, 03:31 PM
If it's something universally-useful, that all users on your system would want to use then putting in PATH somewhere isn't an all-together horrible idea. I'd advise using /usr/local/bin instead of /usr/bin though. /usr/local/bin tends to contain less stuff, and you're less-likely to accidentally mess things up there.

If it's something only you will ever be using (either because you're the only user, or because it's just very tailor-made to suit you) you can create a bin directory in your home folder and add that to your path.



mkdir ~/.bin #I like keeping my personal bin directory hidden
cp myProg.py ~/.bin #copy your program into .bin
chmod -R 700 ~/.bin #make .bin and its contents executable


Finally you need to add .bin to your PATH. Edit ~/.bashrc (assuming you use bash). At the end of the file add a line that reads


export PATH=/home/myUserName/.bin:$PATH

liquidbee
November 4th, 2009, 03:42 PM
Don't do that!



Keep a local directory of python programs.

chmod 750 <myprog.py>
./myprog.py

If you clutter the /usr/bin directory with your own executables, you will end up screwing yourself.

The idea is you run your stuff from under your home directory, do not include '.' in your PATH, don't copy executables to a directory in your PATH -- unless you really know what you are doing, and you don't yet.

That's for what /usr/local/bin is there.

baskar007
November 5th, 2009, 06:22 PM
That's for what /usr/local/bin is there.
So if i put my program into "usr/local/bin",i can call that program by terminal of Alt+F2 ?

liquidbee
November 5th, 2009, 06:31 PM
So if i put my program into "usr/local/bin",i can call that program by terminal of Alt+F2 ?

Yes.

Druke
November 5th, 2009, 07:49 PM
I'm going to have to recommend ve4cib's method, that is the cleanest way to do it.