Can't run Python from cmd line

后端 未结 6 1409
無奈伤痛
無奈伤痛 2020-12-21 02:11

I am a programming (and Python) novice. I am unable to run any python script in command prompt of my WinXP 64-bit laptop. I assigned the path and confirmed it by typing set

相关标签:
6条回答
  • 2020-12-21 02:22

    You're inside the python interpreter not the windows command line.

    To open the windows command line go to

    Start -> All Programs -> Accessories -> Command Prompt

    Then you will need to change into the directory where you have stored hello.py. If it was on your desktop you would do:

    cd Desktop
    

    and then after that you could do:

    python hello.py
    

    and it would work.

    0 讨论(0)
  • 2020-12-21 02:26

    python is the command you use to run the script so you run it in the shell. In Windows, that would be the command prompt (Run > "cmd").

    0 讨论(0)
  • 2020-12-21 02:27

    You should type this

    python hello.py
    

    at the dos/cmd prompt, not inside the Python Interpreter

    0 讨论(0)
  • 2020-12-21 02:33

    Do it like this:

    Go the directory(python32 in my example) and type python hello.py.

    If you only type python in cmd then it'll launch the python interpreter after that python hello.py will return Syntax error.

    enter image description here

    0 讨论(0)
  • 2020-12-21 02:35

    You are typing the command inside the Python shell, do it from the DOS prompt.

    I.e.,

     C:\somepath\> python hello.py
    

    since you already have the python executable on the path (the number 1 problem usually when things don't work), you should be set to go.

    0 讨论(0)
  • 2020-12-21 02:37

    Another way of doing it inside the interpreter is by just importing the name of the module without the .py so for example, in your case:

    >>>import hello
    

    would return

    Hello, World!
    
    0 讨论(0)
提交回复
热议问题