7

I have installed pipenv by pip3.
And it works pipenv -h in script.
But after in crontab, it's not work.

pip3 show pipenv
Location: /home/ubuntu/.local/lib/python3.6/site-packages

my cronjob
21 * * * * cd /home/ubuntu/test; /bin/sh test.sh > /home/ubuntu/test.out 2>&1

test.sh

#!/bin/bash
echo "hi"

python -V
python3 -V
pipenv -h

output hi Python 2.7.12
Python 3.6.3
test.sh: : test.sh: pipenv: not found

how to run pipenv in cronjob in ubuntu? thanks.

Answer:
/home/ubuntu/.local/bin/pipen

beehuang
  • 339
  • 2
  • 18
  • The problem is that cron has a limited environment. Please have a look at [this canonical answer :: why is my crontab not working](https://serverfault.com/questions/449651/why-is-my-crontab-not-working-and-how-can-i-troubleshoot-it). Especially the section _cron runs your command in a restricted environment_. If you do not know where your binary is located you can type the following in the console `which pipenv` – kvantour Jan 19 '18 at 15:24

1 Answers1

17

Try giving the whole path.

Find which pipenv and then run with the absolute path of the same. instead of pipenv -h

In my case it was located in /usr/local/bin/pipenv

Varad
  • 920
  • 10
  • 25
  • Thank u, But I can not find the path. It was not located in `/usr/local/bin/pipenv` in ubuntu. I used pip3 install pipenv. Do u know how to find the actual path in ubuntu16.04? – beehuang Jan 19 '18 at 14:03
  • 1
    Thank u I found in /home/ubuntu/.local/bin – beehuang Jan 19 '18 at 14:15
  • 4
    For future reference: Running `which pipenv` should say where pipenv is located :) – thomasa88 Jun 16 '18 at 13:27