Skip to main content
1 of 2
Lynob
  • 4.5k
  • 13
  • 50
  • 75

how to activate virtualenv when a python script starts?

I want to schedule a python script to run using cron on certain dates, the problem is that in order for example.py to work, example-env has to be activated, is there a way to make example.py activate its own virtualenv whenever cron execute it?

if not, then do i have to create a bash script bash.sh that contains

#!/usr/bin/env bash
workon example-env
python2 example.py

and then schedule that to be executed by cron on certain dates? Or do I have to do something else?

Lynob
  • 4.5k
  • 13
  • 50
  • 75