I want to run each day a python script in a virtual environment by recording it in Windows Task Scheduler. Hence, I need to write a batch that:
- Opens a cmd.exe
- Starts a virtual environment
- Changes the directory to a python project directory
- Invokes the virtual python
I wrote this .bat:
cmd /k "cd /d %USERPROFILE%\python_venv\venv1\Scripts & activate & cd /d %PROJECT_DIR%\src"
python main.py
Of course cmd /k does not terminate, and python main.py is not executed.
Sorry in advance if the answer already exists over the Internet but I was not able to find it or to modify a close answer to suit my needs.
[EDIT] This question is a duplicate of Schedule [Virtualenv Dependent] Python Script with Windows Task Scheduler. This post has also not been answered yet.
[EDIT 2] Found an answer here: Run a python script in virtual environment from windows task scheduler