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)

1

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

1 Comment

This was super helpful, worked for me, thanks R. Bourgeon, you saved me time/money/life essence.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.