1

I installed the 2.5.6 version from http://www.python.org/download/releases/2.5.6/ (the .tgz). It seems to have installed correctly, but I am having problems when I go to use it. I open up the command-line version, and it looks OK, but if I type any commands and try to execute them it gives me errors.

This is my first venture into Python, and I could be doing this completely wrong. I am also unable to change directories using the command line. I have a sample program in a directory: ex1.py. I see the following in my command prompt:

Python 2.7.2 (default, Jun 12 2011, 14:24:46) [MSC v.1500 64-bit (AMD64)] on Windows 32
Type "help", "copyright", "credits" or "license" for more information.
>>>

I entered the following:

>>> python ex1.py

The following message returned:

File "<stdin>", line 1
  python ex1.py
          ^
SyntaxError: Invalid syntax

Now it could be a syntax error, but I do not see anything; it is a simple "Hello world" program. I am not comfortable with the install and fear I may have screwed things up.

2 Answers 2

4

You're supposed to type python ex1.py outside the Python shell, on the command prompt, not inside the Python shell.

3
  • I did this and I am getting a syntax error. My entire program is: Print "test!" I am not sure if i have downloaded a different version but the sample that I am learning from has this as the syntax. I must be missing something.
    – Silspar24
    Jun 28, 2011 at 0:42
  • @Silspar24 - it's print "test!" not Print "test!"
    – Sathyajith Bhat
    Jun 28, 2011 at 2:15
  • Use brackets, print("test")
    – tommyip
    Nov 14, 2014 at 22:06
0

There are a few things that could be wrong, and one that is definitely wrong.

Things that are definitely wrong

  • When executing a file, type python ex1.py from the command prompt, not inside the Python interpreter.

Things that could be wrong

  • If you have Python 3.x installed, when printing "Hello World!" make sure you use brackets in print, ex:

    Right:

    print('Hello World!')

    Wrong:

    print 'Hello World!'

Also, if you have Python 2.7 or earlier installed, this is still a good habit to get into when programming, and will make the eventual transition to 3.x much smoother.

  • You said in your example that you typed Print "Hello World" - in this example the print function/statement should not be capitalized.

You must log in to answer this question.

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