Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

This question already has an answer here:

Hello guys I'm actually new to Terminal and Python. Just started following a Python tuturial on my Ubuntu and I've reached a part where it asks me to save a .py file and open it in Terminal.

Only when I try to type on Terminal $ python egotrip.py I get $: command not found Then I try to type it in python and I get

File "", line 1
    python egotrip.py
                 ^
SyntaxError: invalid syntax

But I mean all names are correct :(

Then I gave also tried /home/anacah/Desktop/python/egotrip.py And I get

Traceback (most recent call last):
  File "", line 1, in 
NameError: name 'home' is not defined

What am I doing wrong? :( can someone please help?

share|improve this question

marked as duplicate by Eliah Kagan, karel, Eric Carvalho, Sylvain Pineau, Seth Sep 11 at 19:18

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

2 Answers 2

up vote 3 down vote accepted

Try using this line in the terminal:
python /home/anacah/Desktop/python/egotrip.py

thereby providing the entire path for the file including the / at the beginning, and see what happens. If it errors out, please edit your initial post with the section 'Additional Information' and paste the error message.

share|improve this answer
    
No way lol thanks a lot to take the time to help a rookie go 'round :) –  Ana Feb 8 '12 at 0:00
    
@Ana, no problem. Note that two things should be considered when running a .py program: (1) where the file is located, (2) where your current 'working directory' is (you can find that with pwd), and (3) whether you are in the directory the file is located in. If you put the full path, like I stated, it should work correctly, but to do the full path, you need to have the initial /, stating "Start at the root of the drive, then use <rest of path> to find the file". –  Thomas W. Feb 8 '12 at 0:07

Change directories to the folder where your .py file is stored. Your command should look like this:

cd /home/anacah/Desktop/python

From your information above, it looks as if you left out the "cd" command. Once in that folder, just type:

python egotrip.py

and it should work!

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.