cron can not find the command pyenv

Viewed 1990

I set up the cron to access to the python environment.

pyenv shell ammt-crawler is work find in command line

this is my init.sh file

#!/usr/bin/env bash

export PATH="${HOME}/.pyenv/scripts:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"

pyenv shell ammt-crawler

but log saying that it can not find the pyenv command

./scripts/init.sh: line 4: pyenv: command not found
./scripts/init.sh: line 5: pyenv: command not found
./scripts/init.sh: line 7: pyenv: command not found

what is the problem?

3 Answers

if in ubuntu 18.04, export PATH=~/.pyenv/shims:~/.pyenv/bin:"$PATH" should be added to ~/.profile

Struggled with the same issue on macos. Eventually bypassed pyenv and activated the python virtual environment directly in the shell script.

#!/bin/bash
source /Users/ptrk/.pyenv/versions/<virtualEnvName>/bin/activate
python ...

if you are using the command directly in your crontab know that it is default shell and not bash. Therefor source won't work, use the following syntax instead:

*/10 * * * * . /Users/ptrk/.pyenv/versions/<virtualEnvName>/bin/activate && python ...
Related