The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> Python Programming
|
few questions about python in linux
Discuss few questions about python in linux in the Python Programming forum on Dev Shed. few questions about python in linux Python Programming forum discussing coding techniques, tips and tricks, and Zope related information. Python was designed from the ground up to be a completely object-oriented programming language.
|
|
 |
|
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

July 5th, 2004, 04:12 PM
|
|
Contributing User
|
|
Join Date: Nov 2003
Location: netherlands
Posts: 51
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!
|

July 5th, 2004, 06:29 PM
|
 |
Mini me.
|
|
Join Date: Nov 2003
Location: Cambridge, UK
|
|
|
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.
Last edited by Grim Archon : July 5th, 2004 at 06:35 PM.
|

July 5th, 2004, 06:50 PM
|
|
Contributing User
|
|
Join Date: Apr 2004
Location: Canada
Posts: 242
Time spent in forums: 11 h 3 m 17 sec
Reputation Power: 0
|
|
Quote: | Originally Posted by Grim Archon
#! /bin/python should also work. |
Shouldn't that be /usr/bin/python?
|

July 5th, 2004, 07:20 PM
|
|
Contributing User
|
|
Join Date: Dec 2001
Location: Houston, TX
Posts: 383
Time spent in forums: 1 h 41 m 27 sec
Reputation Power: 12
|
|
|
No it should be #!/usr/bin/env python like the OP had.
|

July 6th, 2004, 01:57 AM
|
 |
Mini me.
|
|
Join Date: Nov 2003
Location: Cambridge, UK
|
|
 lol
|

July 6th, 2004, 03:35 AM
|
|
Contributing User
|
|
Join Date: Nov 2003
Location: netherlands
Posts: 51
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?
|

July 6th, 2004, 03:41 AM
|
 |
Mini me.
|
|
Join Date: Nov 2003
Location: Cambridge, UK
|
|
|
Looks like env is not marked as executable.
|

July 6th, 2004, 03:54 AM
|
 |
Mini me.
|
|
Join Date: Nov 2003
Location: Cambridge, UK
|
|
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'.
|

July 6th, 2004, 04:08 AM
|
|
Contributing User
|
|
Join Date: Nov 2003
Location: netherlands
Posts: 51
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)?
|

July 6th, 2004, 04:36 AM
|
|
Contributing User
|
|
Join Date: Nov 2003
Location: netherlands
Posts: 51
Time spent in forums: < 1 sec
Reputation Power: 10
|
|
|
ELF support was on already. Any other suggestions?
|

July 6th, 2004, 04:39 AM
|
 |
Mini me.
|
|
Join Date: Nov 2003
Location: Cambridge, UK
|
|
|
Does:
env python
load up the interpreter?
|

July 6th, 2004, 05:40 AM
|
 |
Hello World :)
|
|
Join Date: Mar 2003
Location: Hull, UK
|
|
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
|

July 6th, 2004, 06:27 AM
|
|
Contributing User
|
|
Join Date: Nov 2003
Location: netherlands
Posts: 51
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!
|

July 6th, 2004, 01:15 PM
|
|
Contributing User
|
|
Join Date: Apr 2004
Location: Canada
Posts: 242
Time spent in forums: 11 h 3 m 17 sec
Reputation Power: 0
|
|
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
|

July 6th, 2004, 01:36 PM
|
 |
Banned ;)
|
|
Join Date: Nov 2001
Location: Woodland Hills, Los Angeles County, California, USA
|
|
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
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|