#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    24
    Rep Power
    0

    How to run python with command line?


    Hi guys,
    ok, now I can't even run any program in python without pressing the F5.

    Normally I press F5 to run the program...but I can't seem to be able to run ANY python with command line.

    First, I don't even know where should I type this:

    python filename.py

    I"m using IDLE. Should I just open the Shell and type python filename.py ??? it doesn't work. I need to know at least how to run the program step by step from command line T_T

    Okay, lets say i' ve a python file in C:\windows\desktop\okay.py

    How do I run it?
    I try:
    python C:\windows\desktop\okay.py
    and
    python "C:\windows\desktop\okay.py"
    in the shell, but it doesn't run the program...but if i press F5, it can run it.
  2. #2
  3. Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Dec 2004
    Location
    Meriden, Connecticut
    Posts
    1,797
    Rep Power
    155
    Did you try just reinstalling Python?
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    24
    Rep Power
    0
    no, but I'm sure that it's my syntax error. I got an syntax error.

    or I should put "python filename.py" in somewhere else..probably not in the shell.

    Also, why F5 works for me?

    also, if i type "python filename.py" in MS prompt I get an error saying that it can't recgonized the "python" command.
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    24
    Rep Power
    0
    Oh now I think of it, probably I install the python properly, but I forgot to set environment variable for my windows XP, so it can't detect the command "python" in command prompt.

    Am I right?

    How to set up environment variable?
    Please show me step by step.

    Thx.
  8. #5
  9. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    Wrong shell . You need to type this at the DOS command prompt rather than in IDLE.

    To do this press the Windows-R keys together and type "cmd" in the box that appears – just incase you don't know which the windows key is, its the one with the windows sign on it (next to the space bar).

    From here you will probably need to CD to the directory where you installed Python… on Windows this should be something "C:\Python24\" depending on which version you installed .

    Now you can type:

    python C:\path\to\python\script.py

    Note: you need to replace the path given above with the path to your Python program.

    Two alternatives to this would be to move to the directory (using CD) in which your program is located and simply type the files name, or if all else fails double click your program file. Both of these should run the program with whatever Windows associates .py files with – this can be changed if this isn't already Python.

    Sorry I can't give you an example of this but I'm not running Python on Windows.

    Hope this helps,

    Mark.
    programming language development: www.netytan.com Hula

  10. #6
  11. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    Originally Posted by victorti83plus
    Oh now I think of it, probably I install the python properly, but I forgot to set environment variable for my windows XP, so it can't detect the command "python" in command prompt.

    Am I right?

    How to set up environment variable?
    Please show me step by step.

    Thx.
    As far as I can remember it goes like this:

    Right-click "My Computer" and click "Properties".
    Click on the "Advanced" button.
    Click "Environment Variables".
    Locate the PATH variable and add "C:\Python24\" to it.
    Click "Ok".

    Note: replace the path above with the correct installation directory.

    Anyway, that should do it but I haven't done this myself in a while so I may be a little off here .

    Have fun!

    Mark.
    programming language development: www.netytan.com Hula

  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    24
    Rep Power
    0
    thx it works now

IMN logo majestic logo threadwatch logo seochat tools logo