Whenever I login to my ec2 Ubuntu instance my terminal is like this
(base) ubuntu@ip-xx-xx-xx
When I run my Python script which is converted from a Jupyter notebook with the default conda environment the script runs perfect. The problem starts when I try to make a cronjob.
When the instance starts(I will try to explain as best I can), the ipython that runs the script can't find the packages. Because it's the default conda environment. I thought all I have to do is somehow activate the source bash, but everything failed. What I've tried so far
At this point I don't know what I am missing. All I want, is when the instance start to "activate" the conda environment and with ipython run the script.
I'd take a guess that the virtualenv is being activated in .profile
, which doesn't affect cron.
I'd suggest activating the venv in the crontab line:
SHELL=/bin/bash
[crontab stuff] . /path/to/the/virtualenv/bin/activate && your.py
Setting SHELL=/bin/bash is not really mandatory, but will get you closer to the "usual" environment. If necessary, also set the PATH, cd into the right directory, etc.
A decent way to test is to ssh you@yourserver 'the command above'
If you're having trouble getting the error, try appending &>/tmp/debug.log
to the crontab command.
If you're not sure what the virtualenv path is, try: type activate
(echo $PATH
, print(sys.path)
, etc.)
More info: https://stackoverflow.com/questions/3287038/cron-and-virtualenv#answer-7031758
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments