Search code examples
pythonpyinstallerwindows-task-scheduler

Pyinstaller *.exe in TaskScheduler


i created a small python program and freezed it to an *.exe file with the --noconsole option. When I run the program normally it works. But when I put it in the task scheduler that runs it on startup it does not work anymore.

The program has no ui. I know that it is not working because it is not writing to a log file. The paths in the program are absolute.

Any ideas what can cause this problem?


Solution

  • You will need to do a little troubleshooting to narrow down the problem. I can share some tips.

    1. Make sure you have an exception handler for uncaught exceptions (at the very top) so you are logging those errors to a file. If you don't have one you will never know why your program is crashing. Make sure if you add this you are re-throwing the exception after logging it so the os knows it crashed.
    2. Open the task schedule and run the task manually. Make sure the task is allowed to be ran manually (it's in the configuration). If it is allowed to run manually, then it should have no trouble running automatically.
    3. The user you're running the task with might be different from the user you are manually running it with. You can try removing the --noconsole option while you are trying to figure out the problem. If it is an issue with your logger not having write access where it needs to, you would not see anything in your logs but can see messages in the console.
    4. Make sure the working directory of the task is correct. By default it should use the same directory the app is in, but if a path has been entered it can cause issues.