When I want to run my python applications from commandline (under ubuntu) I have to be in the directory where is the source code app.py and run the application with command
<
Add a shebang: as the top line of the file: #!/usr/bin/python
or #!/usr/bin/python3
(you can use the python -B
to prevent generation of .pyc
files, which is why I don't use /usr/bin/env
)
Make it executable: You will need to do chmod +x app.py
(optional) Add directory to path, so can call it anywhere: Add a directory with your executable to your $PATH
environment variable. How you do so depends on your shell, but is either export PATH=$PATH:/home/you/some/path/to/myscripts
(e.g. Linux distros which use bash) or setenv PATH $PATH:/home/you/some/path/to/myscripts
(e.g. tcsh like in Mac OS X). You will want to put this, for example, in your .bashrc
or whatever startup script you have, or else you will have to repeat this step every time you log in.
app.py
will need to be in the myscripts
(or whatever you name it) folder. You don't even need to call it app.py
, but you can just rename it app
.
If you wish to skip step #3, you can still do ./app
to run it if you are in the same directory.