3

I can't say I'm optimistic. I've looked at this: How to schedule a python script to run from virtual environment via task scheduler and this https://superuser.com/questions/1142185/schedule-virtualenv-dependent-python-script-with-windows-task-scheduler and this: Run a python script in virtual environment from windows task scheduler

But I don't have activate.bat in the scripts subdirectory of my virtual environment. This is a known anaconda bug Anaconda3 activate.bat is not recognized as an internal or external command and fixing it requires uninstalling and reinstalling anaconda. I have so many working scripts and the server runs all the time. I can't monkey around with it and try miniconda, anaconda5.1 etc. etc.

I heard pip -t may be a hack if I can't use a virtual environment in the task scheduler just to force the dependencies into the directory. Is there no other way? i thought pip and anaconda don't work well together

TylerH
  • 20,799
  • 66
  • 75
  • 101

2 Answers2

0

Very easy. Go to start menu and search for environment variable via search option. Append your anadonda bin directory (ex. C:\conda\bin) to PATH variable. You're done

  • How would I do it if it's not my computer, it's on a server running with a service account. Also, doesn't that screw with all the other python that's running. The whole point of this virtual environment is to isolate it from the other scripts that are running fine. – Henrietta Martingale Apr 28 '20 at 13:33
  • Still you can achieve that. On Windows terminal, run: ` SET PATH=C:\conda\bin;%PATH% && conda activate C:\myvirtualenv && python ` – Syed Mishar Newaz Apr 30 '20 at 21:05
  • This one only works for single session. When you close your terminal, it goes and doesn't screw your python installation – Syed Mishar Newaz Apr 30 '20 at 21:06
  • I don't think I understand this session thing. But to me there is no terminal. There is a server on the network running on a generic system user. It's running tasks out of the task scheduler. Presumably they're all run under the same "session". Now one of my tasks needs a different environment than the others. Do I just put this entire set path... string followed by my script in the program/field? – Henrietta Martingale May 09 '20 at 17:41
0

For me it worked with a basic batch file I wrote, that did not need the activate file:

call conda activate your_enviroment
python C:\Users\koo5rt\.conda\envs\mgHadoop\your_file.py

I start the file with this content from the task scheduler

lorenzo
  • 75
  • 6