-1

I double click on my python file, which simply prints Hello world but it only a black thing flashed and disappears. The terminal is not opened. My other PC works fine.

I need to do it this way since the Task Scheduler show the same black thing flash when I run task on executing python script.

I spent 2 hours searching around for solution but nothing works.

My file is C:\temp.py and If I open cmd navigate to this file, it will be executed correctly ( cd C:\ ; then C:\temp.py )

I remove the 3.11 version to install 3.7 version and still not work.

Any help is very much appreciated.

Hong

7
  • Can you check it from terminal? I mean open terminal and navigating there, then running the code with python temp.py to see what happens? Commented Nov 12, 2022 at 3:13
  • 2
    add an input("Enter to continue") at the start and again at the end ... when you double click it opens and runs and closes before you can see it is really the issue Commented Nov 12, 2022 at 3:19
  • If your python script "simply prints Hello world" then there is no reason for the terminal to remain open. The script probably ran correctly, printed out something, then immediately exited. The "black thing" that flashes is probably the terminal that just opens-and-closes really fast. Commented Nov 12, 2022 at 3:33
  • Duplicate of How to stop Python closing immediately when executed in Microsoft Windows Commented Nov 12, 2022 at 3:34
  • You are right. '''input("enter to cont") do make the terminal shows up. For my real code (verified running in 2 other PCs), after double click, the terminal opens and runs correctly. But in this PC it doesn't run. Yes, when I open terminal and run this real code in this trouble PC, it runs as expected. Commented Nov 12, 2022 at 3:43

1 Answer 1

1
input('Press ENTER to exit')

If you add this line to the end of your code, the terminal should wait for your you to press the enter key before closing.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.