Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 5th, 2004, 04:12 PM
darkleaf darkleaf is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Location: netherlands
Posts: 51 darkleaf User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 10
few questions about python in linux

According to the tutorial it might be possible to make the script automatically executable by adding #! /usr/bin/env python at the start. If this and chmod +x script.py isn't working do I need a different program or do I just do anything wrong? I'm running in debian kde but the script works if I just do ' python script.py'

In windows it was possible to make a textpad like interface via new in idle so you can type the script without those >>> and ... lines the interpreter adds to it. Is the linux way using a normal text editor for this (text editor gives the syntax in color when the script's extension is .py)? Like is it even handy to write immediately in the intrepreter if you want to create a program or is that just if you want to do something once and without saving?

Thanks for the help!

Reply With Quote
  #2  
Old July 5th, 2004, 06:29 PM
Grim Archon's Avatar
Grim Archon Grim Archon is offline
Mini me.
Dev Shed Novice (500 - 999 posts)
 
Join Date: Nov 2003
Location: Cambridge, UK
Posts: 783 Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)  Folding Points: 1488 Folding Title: Novice Folder
Time spent in forums: 3 Days 2 h 15 m 57 sec
Reputation Power: 12
Send a message via MSN to Grim Archon
idle should be available - I cant check Debian right now but it is probably in /usr/lib/python21/idle or idlelib (Assuming you are using 3.0r2 stable)

Try #! /bin/env python .

The command
which env should locate it for you

If it is not working then it means that python is not in the PATH of the user running the script. This is a "common" problem I think with CGI scripts because the script is not run as a normal user.

#! /bin/python should also work.
__________________
*** Experimental Python Markup CGI V2 ***

Last edited by Grim Archon : July 5th, 2004 at 06:35 PM.

Reply With Quote
  #3  
Old July 5th, 2004, 06:50 PM
NetBSD NetBSD is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Location: Canada
Posts: 242 NetBSD User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 h 3 m 17 sec
Reputation Power: 0
Send a message via MSN to NetBSD
Quote:
Originally Posted by Grim Archon
#! /bin/python should also work.


Shouldn't that be /usr/bin/python?

Reply With Quote
  #4  
Old July 5th, 2004, 07:20 PM
Strike Strike is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2001
Location: Houston, TX
Posts: 383 Strike User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 41 m 27 sec
Reputation Power: 12
Send a message via ICQ to Strike Send a message via AIM to Strike Send a message via Yahoo to Strike
No it should be #!/usr/bin/env python like the OP had.
__________________
Debian - because life's too short for worrying.
Best. (Python.) IRC bot. ever.

Reply With Quote
  #5  
Old July 6th, 2004, 01:57 AM
Grim Archon's Avatar
Grim Archon Grim Archon is offline
Mini me.
Dev Shed Novice (500 - 999 posts)
 
Join Date: Nov 2003
Location: Cambridge, UK
Posts: 783 Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)  Folding Points: 1488 Folding Title: Novice Folder
Time spent in forums: 3 Days 2 h 15 m 57 sec
Reputation Power: 12
Send a message via MSN to Grim Archon
lol

Reply With Quote
  #6  
Old July 6th, 2004, 03:35 AM
darkleaf darkleaf is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Location: netherlands
Posts: 51 darkleaf User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 10
Quote:
#! /usr/bin/env python

print "hello"



Quote:
philip@debian:~/Desktop$ which env
/usr/bin/env
philip@debian:~/Desktop$ ./test.py
bash: ./test.py: usr/bin/env: bad interpreter: Permission denied
philip@debian:~/Desktop$ python test.py
hello
philip@debian:~/Desktop$


Normal user and root give the same error. what;s wrong?Thanks for the help!

edit I tried all the suggestions for the #! line so maybe I'm calling the script wrong?

Reply With Quote
  #7  
Old July 6th, 2004, 03:41 AM
Grim Archon's Avatar
Grim Archon Grim Archon is offline
Mini me.
Dev Shed Novice (500 - 999 posts)
 
Join Date: Nov 2003
Location: Cambridge, UK
Posts: 783 Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)  Folding Points: 1488 Folding Title: Novice Folder
Time spent in forums: 3 Days 2 h 15 m 57 sec
Reputation Power: 12
Send a message via MSN to Grim Archon
Looks like env is not marked as executable.

Reply With Quote
  #8  
Old July 6th, 2004, 03:54 AM
Grim Archon's Avatar
Grim Archon Grim Archon is offline
Mini me.
Dev Shed Novice (500 - 999 posts)
 
Join Date: Nov 2003
Location: Cambridge, UK
Posts: 783 Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)  Folding Points: 1488 Folding Title: Novice Folder
Time spent in forums: 3 Days 2 h 15 m 57 sec
Reputation Power: 12
Send a message via MSN to Grim Archon
Quote:
Originally Posted by Strike
No it should be #!/usr/bin/env python like the OP had.
- Assuming that python is in the path of the user - which in this case it is.

My original post was based on Redhat 9 which has env located at /bin/env with a logical link at /usr/bin/env.
I guess demonstrating the diffent origins. I find this a laugh since this is the sort of problem env is trying to solve.

Had to unistall Debian as the only machine I have with compatible hardware is running Redhat9 at the mo'.

Reply With Quote
  #9  
Old July 6th, 2004, 04:08 AM
darkleaf darkleaf is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Location: netherlands
Posts: 51 darkleaf User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 10
Quote:
debian:/usr/bin# file env
env: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), stripped
debian:/usr/bin# chmod +x env
debian:/usr/bin# cd /home/philip/Desktop
debian:/home/philip/Desktop# ./test.py
bash: ./test.py: usr/bin/env/: bad interpreter: Permission denied
debian:/home/philip/Desktop#


let me check if I have elf support in the kernel. That could be the problem isn't it (if it's an old executable type I probably have turned it off if it's new I should have it but I'll check it anyway)?

Reply With Quote
  #10  
Old July 6th, 2004, 04:36 AM
darkleaf darkleaf is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Location: netherlands
Posts: 51 darkleaf User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 10
ELF support was on already. Any other suggestions?

Reply With Quote
  #11  
Old July 6th, 2004, 04:39 AM
Grim Archon's Avatar
Grim Archon Grim Archon is offline
Mini me.
Dev Shed Novice (500 - 999 posts)
 
Join Date: Nov 2003
Location: Cambridge, UK
Posts: 783 Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)  Folding Points: 1488 Folding Title: Novice Folder
Time spent in forums: 3 Days 2 h 15 m 57 sec
Reputation Power: 12
Send a message via MSN to Grim Archon
Does:
env python

load up the interpreter?

Reply With Quote
  #12  
Old July 6th, 2004, 05:40 AM
netytan's Avatar
netytan netytan is offline
Hello World :)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2003
Location: Hull, UK
Posts: 2,537 netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 18 h 17 m 47 sec
Reputation Power: 68
Send a message via ICQ to netytan Send a message via AIM to netytan Send a message via MSN to netytan Send a message via Yahoo to netytan
This may be stupid, i dont pretend to be anything more than a noob when it comes to *nix! But, in my experiance, just typing python will start the Python interpreter so you might wana give that a go .

Also, try using the full path to where Python is installed, since that should always work. Oh, and you might want to throw a which python somewhere in there , that is if typing python works.

Hope this helps,

Mark.
__________________
programming language development: www.netytan.com Hula


Reply With Quote
  #13  
Old July 6th, 2004, 06:27 AM
darkleaf darkleaf is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Location: netherlands
Posts: 51 darkleaf User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 10
Hmm figured it out. It looks like I didn't use chmod +x as root but as normal user. It didn't gace an error that I should have been root though. Thanks for the help!

Reply With Quote
  #14  
Old July 6th, 2004, 01:15 PM
NetBSD NetBSD is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Location: Canada
Posts: 242 NetBSD User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 h 3 m 17 sec
Reputation Power: 0
Send a message via MSN to NetBSD
Quote:
Originally Posted by Strike
No it should be #!/usr/bin/env python like the OP had.


Yes, using env is the best way but I was correcting Grim when he said an alternative would be /bin/python when it should be /usr/bin/python. Any distro that installs Python into /bin should be shot.

man 7 hier

Reply With Quote
  #15  
Old July 6th, 2004, 01:36 PM
Scorpions4ever's Avatar
Scorpions4ever Scorpions4ever is offline
Banned ;)
Dev Shed God 9th Plane (9000 - 9499 posts)
 
Join Date: Nov 2001
Location: Woodland Hills, Los Angeles County, California, USA
Posts: 9,406 Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Months 9 h 35 m 45 sec
Reputation Power: 4080
Quote:
Originally Posted by NetBSD
Yes, using env is the best way but I was correcting Grim when he said an alternative would be /bin/python when it should be /usr/bin/python. Any distro that installs Python into /bin should be shot.

man 7 hier

Actually there's no guarantee that #!/usr/bin/python will work either, which is why they recommend #!/usr/bin/env python, becase python isn't necessarily located in /usr/bin either, but env is located in /usr/bin (at least for all the systems I've used). I figure that as a NetBSD user, you're probably well aware of this .
For the record, here are the locations on different OSs/distros, assuming you installed from ports/packages/pkgsrc and didn't muck around with the default install locations:
Code:
Red Hat Linux (7,8,9): /usr/bin/python
FreeBSD: /usr/local/bin/python
OpenBSD: /usr/local/bin/python
NetBSD: /usr/pkg/bin/python
__________________
Up the Irons
What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
"Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
Down with Sharon Osbourne

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > few questions about python in linux

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap