1

I want my Windows computer to automatically run a Python script every day, using the Task Scheduler. I wrote my Python Script using Spyder (Anaconda), and then I wrote a small batch file which looks like this:

set PATH="C:\ProgramData\Anaconda3\lib\site-packages";%PATH%
"C:\ProgramData\Anaconda3\python.exe" "path\to\my\python\script.py"
pause

note that I am manually adding "C:\ProgramData\Anaconda3\lib\site-packages" to my PATH variable, to ensure that my Anaconda Python distribution will correctly import the necessary modules, including pandas and numpy.

But when I run this batch script, the following error happens:

Traceback (most recent call last):
  File "path\to\my\python\script.py", line 10, in <module>
    import pandas as pd
  File "C:\ProgramData\Anaconda3\lib\site-packages\pandas\__init__.py", line 19, in <module>
    "Missing required dependencies {0}".format(missing_dependencies))
ImportError: Missing required dependencies ['numpy']

So it looks like Python wasn't able to import numpy, despite my specific action to add the site-packages folder to the PATH variable.

How can I solve this issue?

EDIT: my question is quite similar to this one Schedule a Python script via batch on windows (using Anaconda)

R. Bourgeon
  • 923
  • 1
  • 9
  • 25
  • 1
    Take a look at this question: https://stackoverflow.com/questions/41859939/python-pandas-missing-required-dependencies-numpy-1 – fabioconcina Dec 05 '19 at 10:55

1 Answers1

4

I finally solved it by writing the following:

call "C:\ProgramData\Anaconda3\Scripts\activate.bat"
python "path\to\my\python\script.py"

The first command enables the Anaconda environment, ensuring that all the installed packages will be correctly imported when requested. Then the Python script is executed.

source https://stackoverflow.com/a/53363567/6103050

R. Bourgeon
  • 923
  • 1
  • 9
  • 25