3

I have a python program which I need to run at a particular day of a month, so I am using crontab for this task and create a shell script to run this python program.

This is part of my shell script:

#!/bin/bash
filepath='file2018'
cd ${filepath}
python3 file.py

When I run the crontab which executes the shell script, the log file shows the following error:

line 9: python3: command not found 

I'm really confused about why this error occurs because I have already install python3 and I can run python3 directly from the command line.

Besides, if I replace python3 with python, the shell script works! My python version is python2, but I have to use python3 for this program, so I have to use python3 instead of python.

My operating system is Linux CentOS.

Hope someone can give me some tips!

1
  • How can you get your terminal to call python3 when you type python? Commented Sep 30, 2022 at 3:28

2 Answers 2

5

You can give the full path to the python3 executable. You can get it using the which python3 command. Try it out.

Sign up to request clarification or add additional context in comments.

Comments

3

in file.py add first line like below and add +x permission to file.py file

#!/usr/bin/python3

it will automatically execute, no need to mention python3 in the script use "which python3" command to know exact path of python3 in your machine

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.