0

For CRON schedule that I am trying to run a .py file... Does the shebang at the top of a .py file need to state the version of python?

#!/usr/bin/env python

If I need Python 3, should this be: #!/usr/bin/env python3

1

Yes. At least for now you need to specify either python or python3.

At some point, python a.k.a Python ver 2.7.16 may be deprecated, and removed from the Raspbian distribution. But when this will happen has been the subject of speculation for some time.

For now, python is version 2, and may be determined as follows:

$ python -V
Python 2.7.16

This, as reported on my Raspbian buster system.

python3 is the newer version of Python; its version determined as follows:

$ python3 -V
Python 3.7.3

And they are literally two separate binaries on your system:

$ which python
/usr/bin/python
$ which python3
/usr/bin/python3
| improve this answer | |
  • Ok ill change the shebang too #!/usr/bin/env python3 cheers thanks.. – HenryHub Jun 30 at 13:31
  • A portion of my script isnt working but some parts are. IE, one try/except retrieves data from a sensor, and another try/except retrieves data from weather API. The weather API works just fine but the my sensor reading isnt... But when running the same .py file (that CRON is using) thru terminal it all works just fine... – HenryHub Jun 30 at 13:33
  • Is that a separate question? If so, please post it as a new question, and be sure to include the relevant portions of your crontab. – Seamus Jun 30 at 13:35
  • @HenryHub May be useful: raspberrypi.stackexchange.com/q/40493/5538 – goldilocks Jun 30 at 14:34
  • "At least for now..." -> Probably a best practice forever, regardless of the OS policy. I'd guess the reason this did not happen with python2 is that it had so many more users than python1 and/or is backward compatible. Also worth considering that there may be a python4 in the future. – goldilocks Jun 30 at 14:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.