Skip to content

Instantly share code, notes, and snippets.

@nmpowell
Last active March 28, 2024 01:27
Show Gist options
  • Save nmpowell/d444820b58f10568b15a082ee4f591cf to your computer and use it in GitHub Desktop.
Save nmpowell/d444820b58f10568b15a082ee4f591cf to your computer and use it in GitHub Desktop.
Windows batch script to run a Python program or script within its virtual environment. This can be called from Windows Task Scheduler.
REM Windows batch script to run 1+ Python program/scripts, sequentially, within their virtual environment. This can be called from Windows Task Scheduler.
set original_dir=%CD%
set venv_root_dir="C:\Python-Venvs\env-name"
cd %venv_root_dir%
call %venv_root_dir%\Scripts\activate.bat
python your_python_script.py <arg1> <arg2> <arg3>
installed_python_cli_program <arg1> <arg2> <arg3>
call %venv_root_dir%\Scripts\deactivate.bat
cd %original_dir%
exit /B 1
@ton77v
Copy link

ton77v commented Jul 14, 2023

Amazing, thanks! This also works from cmd so u can create a shortcut to run on demand etc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment