Results 1 to 5 of 5

Thread: Making python scripts executables

  1. #1
    Join Date
    Oct 2007
    Beans
    140

    Making python scripts executables

    Im having a problem. I may have posted before on help on this part of python but i still dont undertstand.I am sick of using a problem such as dr python or geany which when you execute the program a script is made along with the python script which alows it to execute. Well anyway i want to be able to use gedit and then execute the script.I have tryed adding these lines:

    Which one should work?
    Code:
    #!/usr/bin/python
    def main():
    	print "main"
    main()
    Code:
    #!/usr/bin/python2.5
    def main():
    	print "main"
    main()
    If this line of code worked then I would expect to just double click the python scripts and hope it runs in a terminal.

    How could i fix this?


    thankyou
    Mr.popo

  2. #2
    Join Date
    Nov 2006
    Beans
    Hidden!

    Re: Making python scripts executables

    In the terminal, you can either run:
    python scriptName.py
    Or you can run:
    chmod u+x # do this once
    ./scriptName.py

  3. #3
    Join Date
    Oct 2007
    Beans
    140

    Re: Making python scripts executables

    Thanks.

  4. #4
    Join Date
    Feb 2007
    Beans
    314
    Distro
    Ubuntu 7.04 Feisty Fawn

    Re: Making python scripts executables

    I think it's better to use "/usr/bin/env python" instead of "#!/usr/bin/python", it helps prevents uncompatibilities with other distros.
    <plexr> do you know std c++ ?
    <plexr> or is a weak understanding of VB your only strength
    <ahorse_> oohhhhh he just said the equivalent of *yo momma*
    www.acgla.net <--- My webpage : )

  5. #5
    Join Date
    Oct 2007
    Beans
    130
    Distro
    Ubuntu 8.04 Hardy Heron

    Re: Making python scripts executables

    to get it to run from a double click you have to right click and select "allow execution of this file" (or something similar) - I think this is just a gui way of doing chmod though.

    ps I would personally keep the
    #!/usr/bin/python2.5
    if you are doing anything that specifically requires python 2.5 - python tends to break quite a bit between releases and I have several versions of python installed.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •