Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: Ubuntu & Python

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

    Ubuntu & Python

    I am dabbling with Python, managed to enter into python 'Hello, Wold!' but can't run the program. This is where I am up to...

    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.


    ...and I am uncertain of what to do. I have played with it all day. Can anyone give me some direction???


    Sincerely,


    Scott

  2. #2
    Join Date
    Apr 2007
    Location
    Upstate NY, USA
    Beans
    769
    Distro
    Ubuntu 12.10 Quantal Quetzal

    Re: Ubuntu & Python

    Try:
    Code:
    python ./your_program.py
    Doing this you will not need that first line. That line looks odd to me (not an expert, I just started too) but I think it should just be #! /usr/bin/env python.

    You don't really need it if you use the first method I mentioned and tell it to use python up front..
    Last edited by Terl; August 15th, 2010 at 11:38 AM.

  3. #3
    Join Date
    Oct 2008
    Location
    Maryland, USA
    Beans
    300
    Distro
    Kubuntu 9.10 Karmic Koala

    Re: Ubuntu & Python

    Where are you stuck? Assuming you've named your "Hello, World" program hello.py, what happens when you go to terminal and run the command,

    Code:
    ./hello.py
    ?

    (Next time, ask your programming questions in the "Programming Talk" forum.)
    OpenSUSE: Dell Inspiron 8600 and Gateway GT5678
    MacOS X 10.5.8 PowerBook G4 12"
    Linux user #: 501795

  4. #4
    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 Terl View Post
    Try:
    Code:
    python ./your_program.py
    Doing this you will not need that first line. That line looks odd to me (not an expert, I just started too) but I think it should just be #! /usr/bin/env python.

    You don't really need it if you use the first method I mentioned and tell it to use python up front..
    I get ...
    scott@scott-laptop:~$ ./hello.py
    bash: ./hello.py: Permission denied
    scott@scott-laptop:~$

    and...
    scott@scott-laptop:~$ python ./hello.py
    File "./hello.py", line 1
    Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56)
    ^
    SyntaxError: invalid syntax
    scott@scott-laptop:~$
    ...when I put python first.

    Yeah, I tried that too, with no luck.
    Maybe my syntax is wrong!!!
    I am gonna put this down for the night and have another crack at it tomorrow, we might get some more input here hopefully, by the time I get home from work
    Last edited by Segofam; August 15th, 2010 at 11:45 AM.

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

    Re: Ubuntu & Python

    permission denied is because if you want to run the script without preceding 'python' you have to chmod +x your file first (set as 'standalone' executable).

    case with 'python ...' - there is no permission denied because you tell python 'take this file and run it' - script doesn't need to be +x here. You got a syntax error in your script though
    Last edited by Vaphell; August 15th, 2010 at 12:00 PM.

  6. #6
    Join Date
    Jan 2007
    Beans
    6,540
    Distro
    Ubuntu 13.04 Raring Ringtail

    Re: Ubuntu & Python

    Of course, the other alternative is to install an IDE like idle or geany, which allows you to create and test your code in the same place.

  7. #7
    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 Vaphell View Post
    permission denied is because if you want to run the script without preceding 'python' you have to chmod +x your file first (set as 'standalone' executable).

    case with 'python ...' - there is no permission denied because you tell python 'take this file and run it' - script doesn't need to be +x here. You got a syntax error in your script though
    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???

  8. #8
    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 Paqman View Post
    Of course, the other alternative is to install an IDE like idle or geany, which allows you to create and test your code in the same place.
    Hi Paqman,
    I have installed "IDLE (using Python-2.6)"
    Is that what you are suggesting?

    If it is, I have not been able to run a program through it. In Wiki - somewhere - it says I can do it through edit, but there are no options in my edit tab to perform that function.

    Sincerely,

    Scott

  9. #9
    Join Date
    Jan 2007
    Beans
    6,540
    Distro
    Ubuntu 13.04 Raring Ringtail

    Re: Ubuntu & Python

    Quote Originally Posted by Segofam View Post
    If it is, I have not been able to run a program through it. In Wiki - somewhere - it says I can do it through edit, but there are no options in my edit tab to perform that function.
    Right click on any Python file and go to "Open With" and pick Idle. Then when you click on any Python file it'll launch two Idle windows. The first is the editor, the second is a scratchpad area where you can run things. Hit F5 in the editor to run.

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

    Re: Ubuntu & Python

    Thanks Paqman,
    I had to edit the list when doing a right click on the file to open with IDLE, so that is working now as you said i.e. the two windows.
    I will get back to the online study at http://en.wikibooks.org/wiki/Non-Pro...thon_2.6/Intro
    and...http://hkn.eecs.berkeley.edu/~dyoo/p...tro/index.html
    Any other suggestions are most welcome!
    Kind regards,
    Scott

    PS: How do you make your thread "Solved"?
    I still haven't figured that out!!!

Page 1 of 2 12 LastLast

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
  •