Page 1 of 2 12 Last
  • Jump to page:
    #1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2003
    Location
    netherlands
    Posts
    51
    Rep Power
    12

    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!
  2. #2
  3. Mini me.
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Location
    Cambridge, UK
    Posts
    783
    Rep Power
    14
    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 07:35 PM.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2004
    Location
    Canada
    Posts
    242
    Rep Power
    0
    Originally Posted by Grim Archon
    #! /bin/python should also work.
    Shouldn't that be /usr/bin/python?
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2001
    Location
    Houston, TX
    Posts
    383
    Rep Power
    13
    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.
  8. #5
  9. Mini me.
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Location
    Cambridge, UK
    Posts
    783
    Rep Power
    14
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2003
    Location
    netherlands
    Posts
    51
    Rep Power
    12
    #! /usr/bin/env python

    print "hello"

    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?
  12. #7
  13. Mini me.
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Location
    Cambridge, UK
    Posts
    783
    Rep Power
    14
    Looks like env is not marked as executable.
  14. #8
  15. Mini me.
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Location
    Cambridge, UK
    Posts
    783
    Rep Power
    14
    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'.
  16. #9
  17. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2003
    Location
    netherlands
    Posts
    51
    Rep Power
    12
    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)?
  18. #10
  19. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2003
    Location
    netherlands
    Posts
    51
    Rep Power
    12
    ELF support was on already. Any other suggestions?
  20. #11
  21. Mini me.
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Location
    Cambridge, UK
    Posts
    783
    Rep Power
    14
    Does:
    env python

    load up the interpreter?
  22. #12
  23. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    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

  24. #13
  25. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2003
    Location
    netherlands
    Posts
    51
    Rep Power
    12
    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!
  26. #14
  27. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2004
    Location
    Canada
    Posts
    242
    Rep Power
    0
    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
  28. #15
  29. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,648
    Rep Power
    4248
    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

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
Page 1 of 2 12 Last
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo