python exe runs fine manually, but in windows task scheduler it start and then it crashes

568 views Asked by At

I created an exe with auto-py-to-exe (onefile). the exe works fine, but when I want to run this automatically in windows task manager the exe does start, but throw out an error on the location of my file.
data.json

data.json file is in the same folder as my exe file (I do not use a relative path )
Path

So i wanted to solve this by setting in the windows task scheduler 'start in (optional)' and the path of my folder

Start in then my problem with the path to data.json is solved, but my script crashes at the outlook api to read the mails.

If I run the program manually everything works fine.

Has anyone had the same experience and found a solution?

2

There are 2 answers

0
Biskup On

Make sure you entered a location of where your scipt should be ran in Start in optional text box.

Enter Action Properties -> Actions -> Select your action and click Edit -> Fill your Start in (optional) box with the location of where your script should be started.

This solved my problem that the script couldn't find some of libraries so each time it was ran from task scheduler it crashed. When I started it manually from Explorer then the script was working fine.

After filling in Start in option it works properly.

1
Drust On

Probably doesn't help you, but someone might benefit from this. I used relative paths to read an .env file and the problem was that I highlighted "Run with highest privileges". I could run everything manually, unless I launched it as admin. Fixed it just using full paths in my code