How to stop Python closing immediately when executed in Microsoft Windows

后端 未结 15 2209
北荒
北荒 2020-12-02 22:43

I have just started college and we are going to be using python. We really have done nothing so I have downloaded the program and done some print commands, and that\'s it.

相关标签:
15条回答
  • 2020-12-02 23:19

    If you just want a delay

    from time import *
    
    sleep(20)
    
    0 讨论(0)
  • 2020-12-02 23:19

    The reason why it is closing is because the program is not running anymore, simply add any sort of loop or input to fix this (or you could just run it through idle.)

    0 讨论(0)
  • 2020-12-02 23:20

    Late in here, but in case someone comes here from google---

    Go to the location of your .py file. Press SHIFT then right click anywhere and choose open command prompt from here. Once it's up, Just add

    "python NameOfTheProg.py" to the cmd line

    0 讨论(0)
  • 2020-12-02 23:22

    In Python 2.7 adding this to the end of my py file (if __name__ == '__main__':) works:

    closeInput = raw_input("Press ENTER to exit")
    print "Closing..."
    
    0 讨论(0)
  • 2020-12-02 23:23

    Very simple:

    1. Open command prompt as an administrator.
    2. Type python.exe (provided you have given path of it in environmental variables)

    Then, In the same command prompt window the python interpreter will start with >>>

    This worked for me.

    0 讨论(0)
  • 2020-12-02 23:25

    Well I got similar issue, It is solved by adding Environment Variable.

    Add System Variables in Window

    Name : PYTHONPATH

    Value : C:\Python27;

    Your Python path.

    0 讨论(0)
提交回复
热议问题