Search code examples
python-3.xpandaswindows-10scheduled-tasksopenpyxl

Issue with Windows Task Scheduler and Python script using pandas' read_excel()


Description:

I'm encountering an issue with the Windows Task Scheduler when executing a Python script that utilizes pandas' read_excel() method. Here's the scenario:

  1. I scheduled the Python script to run using the Windows Task Scheduler.
  2. My system has two versions of Python installed, but only one is added to the environment variables.
  3. In the scheduled task, I provided the path to the default Python runtime (version 3.10.7).

Problem:

When I manually trigger the scheduled task, it fails and reports that it cannot find the 'openpyxl' module, which is actually installed (version 3.1.2). Strangely, if I manually trigger the same script using PowerShell with the exact same Python runtime (3.10.7), it executes successfully.

Attempts:

I have tried several approaches, as I previously faced a similar issue due to another dependency, which got resolved after installation. However, in this case, 'openpyxl' was already installed, yet the problem persists only when running the task via Windows Task Scheduler.

Additional Info:

I initially suspected it might be a pandas-related problem, but to verify, I added an import statement for 'openpyxl' at the beginning of the script, and the issue persisted, confirming that it is related to the Windows Task Scheduler.

Has anyone encountered a similar issue with Windows Task Scheduler and pandas? Any suggestions on how to resolve this problem would be highly appreciated. Thank you!


Solution

  • Using virtual environment worked but using default environment still isn't working. My problem is resolved for now.