Page 2 of 2 FirstFirst 12
Results 11 to 13 of 13

Thread: Ubuntu & Python

  1. #11
    Join Date
    Jul 2007
    Location
    Poland
    Beans
    4,499
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: Ubuntu & Python

    thread tools (just above the first post of the thread) -> mark as solved

  2. #12
    Join Date
    Jan 2009
    Beans
    68
    Distro
    Kubuntu 10.10 Maverick Meerkat

    Re: Ubuntu & Python

    Quote Originally Posted by Segofam View Post
    Hi Vaphell,
    I saw that in...
    Running Python Programs in Unix

    If you are using Unix (such as Linux, Mac OSX, or BSD), if you make the program executable with chmod, and have as the first line:
    #!/usr/bin/env python2

    you can run the python program with ./hello.py like any other command.


    ...but how do you do that exactly???

    make the first line of the python file "#!/usr/bin/env python" then, assuming your file is called "hello.py" you need to type the following in the command line in the directory that "hello.py" is located:
    Code:
    chmod +x hello.py
    this command gives the file "executable permission" that is it can be executed as a standalone script.

    What happens is bash looks at the first line of the file and if it starts with "#!" then it executes the command that follows the "#!" with the scriplt file as an argument. So while #!/usr/bin/env python works. so does #!/usr/bin/python.

  3. #13
    Join Date
    Jun 2010
    Location
    Australia, Melb*,SE Sub's
    Beans
    164
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Ubuntu & Python

    Quote Originally Posted by ender4 View Post
    make the first line of the python file "#!/usr/bin/env python" then, assuming your file is called "hello.py" you need to type the following in the command line in the directory that "hello.py" is located:
    Code:
    chmod +x hello.py
    this command gives the file "executable permission" that is it can be executed as a standalone script.

    What happens is bash looks at the first line of the file and if it starts with "#!" then it executes the command that follows the "#!" with the scriplt file as an argument. So while #!/usr/bin/env python works. so does #!/usr/bin/python.
    Oh wow...thanks so much for that! I tried typing that in a few places with no result :-/
    And again, thanks for the explanation too, much appreciated.

Page 2 of 2 FirstFirst 12

Tags for this Thread

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
  •