1

I'm learning python so I may get my foot in the door for a programming career. I'm using the gedit text editor to write the code, however I don't know how to execute the code on ubuntu. If anyone is able to help, I would greatly appreciate as much help as I'm able to get.

10
  • Do you know how to use the terminal? Commands like cd, ls, etc.?
    – muru
    Sep 9, 2014 at 23:09
  • I'm still learning linux. I've been using it on and off for about 7 years but I don't have that much familiarity with it just yet. But I am always willing to learn Sep 9, 2014 at 23:12
  • I swear it's not a duplicate. I read that persons question. My question is not related to it. Sep 9, 2014 at 23:20
  • @wxl we haven't got around to actually running the program, so no errors yet. :)
    – muru
    Sep 9, 2014 at 23:21
  • 1
    @muru despite the weird name, it does actually explain how to run the program, i.e. as referred to in the OP "execute the code."
    – wxl
    Sep 9, 2014 at 23:23

1 Answer 1

4

Open a terminal by pressing CtrlAltT. If you remember where you saved the Python code file (say as first.py in the Desktop folder), use the following command to run it:

python2 ~/Desktop/first.py

If you're using Python 3.X replace python2 with python3 in the above command. On Ubuntu, python2 and python are the same, but it's always good practice to explicitly specify which version you're using.

You can also simply run python2 or python3 to get to an interactive shell. Another option is to use IPython Notebooks.

7
  • I just tried to run it and I got this error: python3: can't open file 'Desktop/leaningpython.py': [Errno 2] No such file or directory Sep 9, 2014 at 23:24
  • yes it's on my desktop that is usually where I save my documents until I move them into another folder Sep 9, 2014 at 23:28
  • OK, try: python3 ~/Desktop/leaningpython.py. Also, please post the output of ls ~/Desktop -l.
    – muru
    Sep 9, 2014 at 23:28
  • as I run it all I'm getting is this: File "/home/darkxearo/Desktop/learningpython.py", line 1 >>> "This text really won't do anything" ^ SyntaxError: invalid syntax Sep 9, 2014 at 23:32
  • 2
    @SeanKirkland there you have it. You haven't written valid Python code yet. :)
    – muru
    Sep 9, 2014 at 23:33

Not the answer you're looking for? Browse other questions tagged .