LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 03-22-2009, 03:50 PM   #1
trist007
Senior Member
 
Registered: May 2008
Distribution: Slackware
Posts: 1,004

Rep: Reputation: 67
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?
 
Old 03-22-2009, 04:12 PM   #2
sycamorex
LQ Veteran
 
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,595
Blog Entries: 1

Rep: Reputation: 1046Reputation: 1046Reputation: 1046Reputation: 1046Reputation: 1046Reputation: 1046Reputation: 1046Reputation: 1046
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?

Last edited by sycamorex; 03-22-2009 at 04:14 PM.
 
Old 03-22-2009, 04:23 PM   #3
trist007
Senior Member
 
Registered: May 2008
Distribution: Slackware
Posts: 1,004

Original Poster
Rep: Reputation: 67
sweetness, thanks man.
 
Old 03-22-2009, 05:02 PM   #4
tuxdev
Senior Member
 
Registered: Jul 2005
Distribution: Slackware
Posts: 2,014

Rep: Reputation: 115Reputation: 115
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.
 
Old 03-22-2009, 07:13 PM   #5
treed
Member
 
Registered: Sep 2003
Posts: 45

Rep: Reputation: 15
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
 
Old 03-22-2009, 09:21 PM   #6
trist007
Senior Member
 
Registered: May 2008
Distribution: Slackware
Posts: 1,004

Original Poster
Rep: Reputation: 67
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Review: Programming in Python 3: A Complete Introduction to the Python Language LXer Syndicated Linux News 0 01-26-2009 05:50 AM
python update - Unable to load GTK2 Python bindings: No module named gtk itpedersen Linux - Software 2 10-03-2008 04:44 AM
LXer: Charming Python: Python elegance and warts, Part 2 LXer Syndicated Linux News 0 08-31-2007 09:40 AM
LXer: Move to python 2.4 / Changing the packaging style for python packages LXer Syndicated Linux News 0 06-13-2006 08:54 PM
python problem - compiled from source - python -V still showing old version txm123 Linux - Newbie 1 02-15-2006 12:05 PM


All times are GMT -5. The time now is 07:32 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration