Python script doesn't work with double click

前端 未结 1 995
梦如初夏
梦如初夏 2021-01-05 18:27

I have a very basic problem, but I cannot find a solution in older answers. When I double click on a python script, I can see a prompt flashing but nothing happens. If I ope

1条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-05 19:23

    Make sure that the script includes this snippet of code:

    if __name__ == "__main__":
        # call your code here
        main()
    

    That's the execution entry point for a script running from the command line, like the main() function in C/C++/Java/C#. Read more about it in this post.

    Also, don't forget the obvious - give the right execution permissions to the script, make sure that the python.exe command is available in the %PATH% environment variable, and so on.

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