Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Python Basics Types and Branching If, Else and Elif

kevin nadjarian
kevin nadjarian
1,498 Points

Python : SyntaxError: invalid syntax

Whatever I do, I receive a Python error:

python hello.py                                                                              

SyntaxError: invalid syntax                                                                      
>>> python hello.py                                                                              
  File "<stdin>", line 1                                                                         
    python hello.py                                                                              
               ^                                                                                 
SyntaxError: invalid syntax

Tried to change the script from the courses or even from external template, always have the same issue

3 Answers

Looks like your problem is that you are trying to run python hello.py from within the Python interpreter, which is why you're seeing that traceback.

Make sure you're out of the interpreter, then run the python hello.py command from bash or command prompt or whatever.

kevin nadjarian
kevin nadjarian
1,498 Points

Yes ... that was it !

Thank you !

I'm getting the same error and I don't understand what to do

Jeffrey Vierra
Jeffrey Vierra
25,404 Points

Hi Mitchel,

I was getting the same error. I found a resolution by upgrading my Python 2.3 to version 3. I'm using a Mac terminal to test out all my Python code. A simple google search "how to upgrade python 2.7 to three" should be a good place to start for you.

Good luck.