Hi, I am trying to schedule a python compiled file to run using windows scheduler. But it does'nt run successfully

The script writes to a SQL server database installed on the same machine as python and the script resides on the same machine.
The script imports the urllib, sys, threading, datetime, optparse, csv & odbc modules.

What am I missing?

Thanks.

Dani AI

Generated

A few concise, practical checks that usually fix Windows Task Scheduler + Python jobs. This follows the original back-and-forth from and : the problem space typically comes down to how the task is invoked, the runtime environment it runs under, and how external resources (ODBC/SQL) are accessed.

  • Always call the interpreter explicitly and use absolute paths. Put the full path to python.exe and the full path to your script in the task Action. Set the task’s "Start in" to the script folder so relative file ops behave predictably.
  • Don’t rely on user-specific settings. Create ODBC DSNs as System (not User) if the scheduled account needs them. If using Windows authentication, grant the scheduled account database rights. Mismatched bitness (32-bit Python vs 64-bit ODBC driver) is a common silent failure.
  • Capture stdout/stderr so you can see failures. Run the job manually using the same account the scheduler uses to reproduce permission/ODBC errors. Check Task Scheduler History and Windows Event Viewer for task-level errors.

Example Action and a small wrapper that logs output:

"C:\Python39\python.exe" "C:\Scripts\myscript.py"

Example batch wrapper (schedule the .bat instead to get logs):

@echo off
"C:\Python39\python.exe" "C:\Scripts\myscript.py" >> "C:\Logs\myscript.log" 2>&1

If problems persist, verify environment variables (PATH/PYTHONPATH) available to the scheduled account, test DB connectivity from that account (e.g., with a tiny Python test or sqlcmd), and confirm no network drive mappings are required (use UNC paths). Microsoft’s Task Scheduler docs and Python’s Windows guide are good references: Task Scheduler start page and Using Python on Windows.

Recommended Answers

All 2 Replies

Well ... you have to give us something!!!
the error message u get for a start....

Does ur scheduler start the script in the first place??

I had a similar problem once. I didn't include the Run as username in the scheduler...:$

So jus let us know what u get...

Nevermind,
I figured out my mistake. I am new to python so I was compiling the script the wrong way by saving it as .pyc file.
I compiled the script using the py_compile module and everything works fine now.

Thanks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.