cron not executing python3












1















I am running Raspbian Stretch and have a python 3 script that executes correctly when I am in the relevant directory and input it in the command line as:



sudo python3 Example.py


The shebang #! line is in the script as follows:



 #!/usr/bin/env python3


And made the script executable with:



sudo chmod +x Example.py


I've tried several variation of below within crontab -e to no avail



10 * * * * python3 /home/pi/Desktop/Example.py










share|improve this question



























    1















    I am running Raspbian Stretch and have a python 3 script that executes correctly when I am in the relevant directory and input it in the command line as:



    sudo python3 Example.py


    The shebang #! line is in the script as follows:



     #!/usr/bin/env python3


    And made the script executable with:



    sudo chmod +x Example.py


    I've tried several variation of below within crontab -e to no avail



    10 * * * * python3 /home/pi/Desktop/Example.py










    share|improve this question

























      1












      1








      1








      I am running Raspbian Stretch and have a python 3 script that executes correctly when I am in the relevant directory and input it in the command line as:



      sudo python3 Example.py


      The shebang #! line is in the script as follows:



       #!/usr/bin/env python3


      And made the script executable with:



      sudo chmod +x Example.py


      I've tried several variation of below within crontab -e to no avail



      10 * * * * python3 /home/pi/Desktop/Example.py










      share|improve this question














      I am running Raspbian Stretch and have a python 3 script that executes correctly when I am in the relevant directory and input it in the command line as:



      sudo python3 Example.py


      The shebang #! line is in the script as follows:



       #!/usr/bin/env python3


      And made the script executable with:



      sudo chmod +x Example.py


      I've tried several variation of below within crontab -e to no avail



      10 * * * * python3 /home/pi/Desktop/Example.py







      raspbian-stretch python-3 cron






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 2 hours ago









      Dan B RaelinDan B Raelin

      257




      257






















          2 Answers
          2






          active

          oldest

          votes


















          2














          As is typical with crontab issues. The environment is not the same as your user or even a sudo/root shell , and env python3 may not return anything (env simply searches through



          Instead you should explicitly use the full path of python which can be found either as which python3 or which $(env python3) and use that full path in your cronttab (typically /usr/bin/python3 but it is also valid to use one installed elsewhere , e.g. a virtualenv directory)






          share|improve this answer
























          • Note shebangs are ignored when called script is called explicitly as argument to python

            – crasic
            2 hours ago











          • The script should also cd <relevant directory>.

            – Ingo
            26 mins ago



















          1














          Try the following in crontab:



          sudo python3 /home/pi/Example.py



          You need the full path to Example.py



          You don't really need the shebang.



          Or sudo crontab -e for the root crontab with:



          python3 /home/pi/Example.py






          share|improve this answer








          New contributor




          Steve Amor is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.





















          • The script should also cd <relevant directory>.

            – Ingo
            24 mins ago













          Your Answer






          StackExchange.ifUsing("editor", function () {
          return StackExchange.using("schematics", function () {
          StackExchange.schematics.init();
          });
          }, "cicuitlab");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "447"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fraspberrypi.stackexchange.com%2fquestions%2f94818%2fcron-not-executing-python3%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          2














          As is typical with crontab issues. The environment is not the same as your user or even a sudo/root shell , and env python3 may not return anything (env simply searches through



          Instead you should explicitly use the full path of python which can be found either as which python3 or which $(env python3) and use that full path in your cronttab (typically /usr/bin/python3 but it is also valid to use one installed elsewhere , e.g. a virtualenv directory)






          share|improve this answer
























          • Note shebangs are ignored when called script is called explicitly as argument to python

            – crasic
            2 hours ago











          • The script should also cd <relevant directory>.

            – Ingo
            26 mins ago
















          2














          As is typical with crontab issues. The environment is not the same as your user or even a sudo/root shell , and env python3 may not return anything (env simply searches through



          Instead you should explicitly use the full path of python which can be found either as which python3 or which $(env python3) and use that full path in your cronttab (typically /usr/bin/python3 but it is also valid to use one installed elsewhere , e.g. a virtualenv directory)






          share|improve this answer
























          • Note shebangs are ignored when called script is called explicitly as argument to python

            – crasic
            2 hours ago











          • The script should also cd <relevant directory>.

            – Ingo
            26 mins ago














          2












          2








          2







          As is typical with crontab issues. The environment is not the same as your user or even a sudo/root shell , and env python3 may not return anything (env simply searches through



          Instead you should explicitly use the full path of python which can be found either as which python3 or which $(env python3) and use that full path in your cronttab (typically /usr/bin/python3 but it is also valid to use one installed elsewhere , e.g. a virtualenv directory)






          share|improve this answer













          As is typical with crontab issues. The environment is not the same as your user or even a sudo/root shell , and env python3 may not return anything (env simply searches through



          Instead you should explicitly use the full path of python which can be found either as which python3 or which $(env python3) and use that full path in your cronttab (typically /usr/bin/python3 but it is also valid to use one installed elsewhere , e.g. a virtualenv directory)







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 2 hours ago









          crasiccrasic

          2,256318




          2,256318













          • Note shebangs are ignored when called script is called explicitly as argument to python

            – crasic
            2 hours ago











          • The script should also cd <relevant directory>.

            – Ingo
            26 mins ago



















          • Note shebangs are ignored when called script is called explicitly as argument to python

            – crasic
            2 hours ago











          • The script should also cd <relevant directory>.

            – Ingo
            26 mins ago

















          Note shebangs are ignored when called script is called explicitly as argument to python

          – crasic
          2 hours ago





          Note shebangs are ignored when called script is called explicitly as argument to python

          – crasic
          2 hours ago













          The script should also cd <relevant directory>.

          – Ingo
          26 mins ago





          The script should also cd <relevant directory>.

          – Ingo
          26 mins ago













          1














          Try the following in crontab:



          sudo python3 /home/pi/Example.py



          You need the full path to Example.py



          You don't really need the shebang.



          Or sudo crontab -e for the root crontab with:



          python3 /home/pi/Example.py






          share|improve this answer








          New contributor




          Steve Amor is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.





















          • The script should also cd <relevant directory>.

            – Ingo
            24 mins ago


















          1














          Try the following in crontab:



          sudo python3 /home/pi/Example.py



          You need the full path to Example.py



          You don't really need the shebang.



          Or sudo crontab -e for the root crontab with:



          python3 /home/pi/Example.py






          share|improve this answer








          New contributor




          Steve Amor is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.





















          • The script should also cd <relevant directory>.

            – Ingo
            24 mins ago
















          1












          1








          1







          Try the following in crontab:



          sudo python3 /home/pi/Example.py



          You need the full path to Example.py



          You don't really need the shebang.



          Or sudo crontab -e for the root crontab with:



          python3 /home/pi/Example.py






          share|improve this answer








          New contributor




          Steve Amor is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.










          Try the following in crontab:



          sudo python3 /home/pi/Example.py



          You need the full path to Example.py



          You don't really need the shebang.



          Or sudo crontab -e for the root crontab with:



          python3 /home/pi/Example.py







          share|improve this answer








          New contributor




          Steve Amor is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.









          share|improve this answer



          share|improve this answer






          New contributor




          Steve Amor is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.









          answered 56 mins ago









          Steve AmorSteve Amor

          111




          111




          New contributor




          Steve Amor is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.





          New contributor





          Steve Amor is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.






          Steve Amor is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.













          • The script should also cd <relevant directory>.

            – Ingo
            24 mins ago





















          • The script should also cd <relevant directory>.

            – Ingo
            24 mins ago



















          The script should also cd <relevant directory>.

          – Ingo
          24 mins ago







          The script should also cd <relevant directory>.

          – Ingo
          24 mins ago




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Raspberry Pi Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fraspberrypi.stackexchange.com%2fquestions%2f94818%2fcron-not-executing-python3%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Why is a white electrical wire connected to 2 black wires?

          Waikiki

          What are all the squawk codes?