-1

I'm using Amazon Linux with Python 2.7.16 preinstalled. Currently, I'm doing a cron job, trying to run python in a shell script using Python 3.7.3. I have it available at /usr/local/bin/python3.7 and alias python=python3.7 in ~/.bashrc.

However, when I call which python in the shell script. I'm getting /usr/bin/python instead. I have tried export PATH="/usr/local/bin:$PATH" but failed because is searching for python instead of python3.7.

Ultimately, when I run any python command in the shell script, I would like to reference /usr/local/bin/python3.7 without explicitly refering to it.

Any help is appreciated. Thanks!

KY Leung
  • 103
  • 1
  • 9
  • Possible duplicate of [Scheduling a python 3.6 script in using crontab/cron](https://stackoverflow.com/q/45740940/608639), [How do I setup a cron to run specifically with python3?](https://stackoverflow.com/q/57894681/608639), [Crontab not running my python script](https://stackoverflow.com/questions/12534135), etc. Also see [How to check if a program exists from a Bash script?](https://stackoverflow.com/q/592620/608639), [How to check if command exists in a shell script?](https://stackoverflow.com/q/7522712/608639) and friends. – jww Sep 15 '19 at 18:32

2 Answers2

0

Try to create symbolic link to the binary

ln -s /usr/local/bin/python3.7 /usr/bin/python

if the file under /usr/bin/python already exists (it probably does), then rename it or backup it in other way.

(Similar SO question)

Kryštof Řeháček
  • 1,965
  • 1
  • 16
  • 28
0

You can use symbolic link to solve this :

export PATH=/usr/local/bin:$PATH
unlink /usr/local/bin/python
ln -s /usr/local/bin/python3.7 /usr/local/bin/python
Ravi Sharma
  • 162
  • 1
  • 3