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.
1 Answer
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.
-
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 ofls ~/Desktop -l
.– muruSep 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. :)– muruSep 9, 2014 at 23:33
cd
,ls
, etc.?