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:
- the environment required by
pyenv
- the non-interactive shell of cronjob
UPDATED BIG QUESTION
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
00. (for reference) Bash startup
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. Crontab
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
II. Project Folder
# 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
What I've tried and know
- Pointing directly at the .profile and .bashrc doesn't work
run.sh
will run okay; it's thepipenv
step that fails- Scheduling other non-pipenv commands work fine
pyenv init
block
- Placed in the
BASH_ENV
file, the cronjob doesn't run at all - Placed in the
run.sh
, the cronjob now runs, but thepipenv run
still fails
pipenv related
- I've tried pipenv shell; which python to use that one in the crontab enjoy -- no cigar