Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


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

Rep: Reputation: 69
How do I make python programs run without entering the command python?

I want to be able to do

sudo ./

instead of always having to do

sudo python

What do I need to change?
Old 03-22-2009, 03:12 PM   #2
LQ Veteran
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,825
Blog Entries: 1

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

#!/usr/bin/env python

your program ......
Then you need to make the script executable:
chmod +x
After that you can either execute your python script by navigating to the directory
with the scripts and running ./ 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 03:14 PM.
Old 03-22-2009, 03:23 PM   #3
Senior Member
Registered: May 2008
Distribution: Slackware
Posts: 1,033

Original Poster
Rep: Reputation: 69
sweetness, thanks man.
Old 03-22-2009, 04:02 PM   #4
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, 06:13 PM   #5
Registered: Sep 2003
Posts: 45

Rep: Reputation: 15

You can install ipython for realtime action

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, 08:21 PM   #6
Senior Member
Registered: May 2008
Distribution: Slackware
Posts: 1,033

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


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 04:50 AM
python update - Unable to load GTK2 Python bindings: No module named gtk itpedersen Linux - Software 2 10-03-2008 03:44 AM
LXer: Charming Python: Python elegance and warts, Part 2 LXer Syndicated Linux News 0 08-31-2007 08:40 AM
LXer: Move to python 2.4 / Changing the packaging style for python packages LXer Syndicated Linux News 0 06-13-2006 07:54 PM
python problem - compiled from source - python -V still showing old version txm123 Linux - Newbie 1 02-15-2006 11:05 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:01 AM.

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