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!
-
How can you get your terminal to call python3 when you type python?Evan Erickson– Evan Erickson2022年09月30日 03:28:33 +00:00Commented Sep 30, 2022 at 3:28
2 Answers 2
You can give the full path to the python3 executable. You can get it using the which python3 command. Try it out.
Comments
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