-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

HnV
  • 9
  • 3
  • 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? – Parham Alvani Nov 12 '22 at 03: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 – Joran Beasley Nov 12 '22 at 03: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. – Gino Mempin Nov 12 '22 at 03:33
  • Duplicate of [How to stop Python closing immediately when executed in Microsoft Windows](https://stackoverflow.com/q/12375173/2745495) – Gino Mempin Nov 12 '22 at 03: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. – HnV Nov 12 '22 at 03:43
  • When I put ```'''input("enter to cont")``` in my real code and double click, the terminal shows. after hit enter, terminal close immediately. I can run this real code in terminal as normal. – HnV Nov 12 '22 at 03:58
  • OK, I found it. somehow some package, like schedule, is not run in my terminal. I have to install them and now it runs. Thank you. – HnV Nov 12 '22 at 04:12

1 Answers1

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.

9Limes
  • 30
  • 8