How do I run a cronjob with a python virtual environment?

前端 未结 3 545
灰色年华
灰色年华 2020-12-21 03:30

Usually I SSH into my EC2 instance and run:

source MYVENV/bin/activate

How do I set my cronjob to activate the virtual environment? My Django sc

3条回答
  •  隐瞒了意图╮
    2020-12-21 04:06

    you can create a single wrapper bash script for executing your Django script. See the example below.

    #!/bin/bash -l       // this should pick up your ~/.bash_profile environment variables
    
    cd /path to project dir/   // set it up if your project is not in python path
    
    source /Users//.virtualenvs/dslab/bin/activate // this activates your environment 
    
    python /home/script.py   // run your script
    

提交回复
热议问题