I'm on Ubuntu 20.04, and I am having issues setting up the crontab correctly using pyenv
+ pipenv
together. Simply adding pipenv run python script.py
to the cronjob does not work; I think it may be due to:
pyenv
How do I use /home/jennings/.pyenv/shims/pipenv
correctly in crontab??
I've checked $?
for pipenv -v
in run.sh
scheduled in crontab, and it fails.
https://github.com/pyenv/pyenv#advanced-configuration
pyenv
requires these entries in these startup files for interactive/login shells I don't understand how to translate this to a non-interactive cronjob call. How do I set up my BASH_ENV to emmulate these environents below?
https://stackoverflow.com/a/9954208/9335288
# ~/.profile
eval "$(pyenv init --path)"
if command -v pyenv 1>/dev/null 2>&1; then
eval "$(pyenv init --path)"
fi
# ~/.bashrc:
export PYENV_ROOT="$HOME/.pyenv"
I am trying to effectively write a .profile for the cronjob... but if you a better solution, please let me know.
# CRONTAB
SHELL=/bin/bash
BASH_ENV="home/jennings/.custom_bash_env
# BASH_ENV="home/jennings/.profile"
# BASH_ENV="home/jennings/.bashrc"
* * * * * cd $PROJECT_DIR; ./run.sh
# BASH_ENV:
Should I point to .profile or .bashrc instead?*
# PYENV
#eval "$(pyenv init --path)"
#if command -v pyenv 1>/dev/null 2>&1; then
# eval "$(pyenv init --path)"
#fi
# ENV VARIABLES
PYENV_ROOT="/home/jennings/.pyenv"
PYTHONPATH=$SOMEPLACE
PATH=all:of:them:paths
# run.sh:
#!/usr/bin/bash
# PYENV
eval "$(pyenv init --path)"
if command -v pyenv 1>/dev/null 2>&1; then
eval "$(pyenv init --path)"
fi
# actual pipenv command I'm trying to run
pipenv run python main.py
# main.py:
import this
# Does some python and logging
run.sh
will run okay; it's thepipenv
step that failspyenv init
blockBASH_ENV
file, the cronjob doesn't run at allrun.sh
, the cronjob now runs, but the pipenv run
still failsCron has a limited environment. You have to declare the full path to the pipenv executable. Instead of using pipenv run python script.py
you should use /usr/local/bin/pipenv run python script.py
.
In your case the full path can be different which pipenv
will give you the proper path.
This is explained in this post how to run pipenv in cronjob in ubuntu?