LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   How do I make python programs run without entering the command python? (https://www.linuxquestions.org/questions/programming-9/how-do-i-make-python-programs-run-without-entering-the-command-python-713604/)

trist007 03-22-2009 02:50 PM

How do I make python programs run without entering the command python?
 
I want to be able to do

sudo ./program.py

instead of always having to do

sudo python program.py

What do I need to change?

sycamorex 03-22-2009 03:12 PM

You need to add a python 'shebang' to the beginning of your script (so that the system knows how to interpret the commands)

Quote:

#!/usr/bin/env python

your program ......
Then you need to make the script executable:
Quote:

chmod +x yourscript.py
After that you can either execute your python script by navigating to the directory
with the scripts and running ./yourscript.py or you can place you scripts in a certain
directory and add it to your $PATH.

btw, are you sure you really need to run your python programs using sudo?

trist007 03-22-2009 03:23 PM

sweetness, thanks man.

tuxdev 03-22-2009 04:02 PM

I'm seconding sycamorex's concerns about running python programs with sudo. Unless the you've spent special care hardening the scripts, it's almost guaranteed that you have a $PATH substitution or an injection vulnerability.

treed 03-22-2009 06:13 PM

Alternative
 
You can install ipython for realtime action
http://ipython.scipy.org/moin/

I used this when I want to see what my program is doing. Also it gives you all the classes and object information.

Here is an example:

In [1]: import os

In [2]: os.
Display all 221 possibilities? (y or n)
os.__all__ os.__builtins__
os.__class__ os.__delattr__
os.__dict__ os.__doc__
os.__file__ os.__getattribute__
os.__hash__ os.__init__
os.__name__ os.__new__
os.__reduce__ os.__reduce_ex__
os.__repr__ os.__setattr__
os._copy_reg os._Environ
os._execvpe os._exists
os._exit os._get_exports_list
os._make_stat_result os._make_statvfs_result
os._pickle_stat_result os._pickle_statvfs_result
os._spawnvef os.abort
os.access os.altsep
os.chdir os.chmod
os.chown os.chroot

trist007 03-22-2009 08:21 PM

I guess I'm in the habit of running commands with sudo. I'm thinking that since the python program opens up a socket that it may need root privileges. But yeah, I'll try running it as user. Unless there is a group I can add user to so that he can open sockets.


All times are GMT -5. The time now is 09:45 PM.