How to run an .ipynb Jupyter Notebook from terminal?











up vote
73
down vote

favorite
28












I have some code in a .ipynb file and got it to the point where I don't really need the "interactive" feature of IPython Notebook. I would like to just run it straight from a Mac Terminal Command Line.



Basically, if this were just a .py file, I believe I could just do python filename.py from the command line. Is there something similar for a .ipynb file?










share|improve this question
























  • Something like this: github.com/paulgb/runipy ?
    – idjaw
    Feb 22 '16 at 3:37










  • Something like that. I have some input statements in my ipython notebook, and it seems to have trouble with these
    – Vincent
    Feb 22 '16 at 3:48















up vote
73
down vote

favorite
28












I have some code in a .ipynb file and got it to the point where I don't really need the "interactive" feature of IPython Notebook. I would like to just run it straight from a Mac Terminal Command Line.



Basically, if this were just a .py file, I believe I could just do python filename.py from the command line. Is there something similar for a .ipynb file?










share|improve this question
























  • Something like this: github.com/paulgb/runipy ?
    – idjaw
    Feb 22 '16 at 3:37










  • Something like that. I have some input statements in my ipython notebook, and it seems to have trouble with these
    – Vincent
    Feb 22 '16 at 3:48













up vote
73
down vote

favorite
28









up vote
73
down vote

favorite
28






28





I have some code in a .ipynb file and got it to the point where I don't really need the "interactive" feature of IPython Notebook. I would like to just run it straight from a Mac Terminal Command Line.



Basically, if this were just a .py file, I believe I could just do python filename.py from the command line. Is there something similar for a .ipynb file?










share|improve this question















I have some code in a .ipynb file and got it to the point where I don't really need the "interactive" feature of IPython Notebook. I would like to just run it straight from a Mac Terminal Command Line.



Basically, if this were just a .py file, I believe I could just do python filename.py from the command line. Is there something similar for a .ipynb file?







python jupyter-notebook ipython nbconvert






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 11 at 4:54









Borealis

2,39193990




2,39193990










asked Feb 22 '16 at 3:35









Vincent

1,19631630




1,19631630












  • Something like this: github.com/paulgb/runipy ?
    – idjaw
    Feb 22 '16 at 3:37










  • Something like that. I have some input statements in my ipython notebook, and it seems to have trouble with these
    – Vincent
    Feb 22 '16 at 3:48


















  • Something like this: github.com/paulgb/runipy ?
    – idjaw
    Feb 22 '16 at 3:37










  • Something like that. I have some input statements in my ipython notebook, and it seems to have trouble with these
    – Vincent
    Feb 22 '16 at 3:48
















Something like this: github.com/paulgb/runipy ?
– idjaw
Feb 22 '16 at 3:37




Something like this: github.com/paulgb/runipy ?
– idjaw
Feb 22 '16 at 3:37












Something like that. I have some input statements in my ipython notebook, and it seems to have trouble with these
– Vincent
Feb 22 '16 at 3:48




Something like that. I have some input statements in my ipython notebook, and it seems to have trouble with these
– Vincent
Feb 22 '16 at 3:48












5 Answers
5






active

oldest

votes

















up vote
55
down vote



accepted










From the command line you can convert a notebook to python with this command:



ipython nbconvert --to python <YourNotebook>.ipynb


You may have to install the python mistune package:



sudo pip install mistune





share|improve this answer























  • This is simply the command line equivalent of @Eric correct answer.
    – ditkin
    Feb 22 '16 at 3:56






  • 7




    Subcommand ipython nbconvert is deprecated in favor of jupyter nbconvert
    – PenguinEngineer
    Nov 6 '17 at 17:33










  • I don't think this answer is correct. II realise it works but the question is how to run .ipynb from terminal, not how to convert it into a .py and then run it.
    – giac_man
    Nov 23 at 12:48


















up vote
96
down vote













nbconvert allows you to run notebooks with the --execute flag:



jupyter nbconvert --execute <notebook>


If you want to run a notebook and produce a new notebook, you can add --to notebook:



jupyter nbconvert --execute --to notebook <notebook>


Or if you want to replace the existing notebook with the new output:



jupyter nbconvert --execute --to notebook --inplace <notebook>


Since that's a really long command, you can use an alias:



alias nbx="jupyter nbconvert --execute --to notebook"
nbx [--inplace] <notebook>





share|improve this answer





















  • This seems not to work behind conda virtual environment
    – Ramesh-X
    May 22 at 8:44






  • 1




    This turns the notebook into a static HTML page
    – Jim Daniël Teunis
    Sep 29 at 15:25


















up vote
24
down vote













You can export all your code from .ipynb and save it as a .py script. Then you can run the script in your terminal.



code export sample



Hope it helps.






share|improve this answer




























    up vote
    4
    down vote













    For new version instead of:



    ipython nbconvert --to python <YourNotebook>.ipynb


    You can use jupyter instend of ipython:



    jupyter nbconvert --to python <YourNotebook>.ipynb





    share|improve this answer




























      up vote
      1
      down vote













      Update with quoted comment by author for better visibility:




      Author's note "This project started before Jupyter's execute API, which is now the recommended way to run notebooks from the command-line. Consider runipy deprecated and unmaintained." – Sebastian Palma




      Install runipy library that allows running your code on terminal



      pip install runipy


      After just compiler your code:



      runipy <YourNotebookName>.ipynb


      You can try cronjob as well. All information is here






      share|improve this answer



















      • 7




        Author's note "This project started before Jupyter's execute API, which is now the recommended way to run notebooks from the command-line. Consider runipy deprecated and unmaintained."
        – Sebastian Palma
        Mar 23 at 15:15











      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      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',
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      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%2fstackoverflow.com%2fquestions%2f35545402%2fhow-to-run-an-ipynb-jupyter-notebook-from-terminal%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      5 Answers
      5






      active

      oldest

      votes








      5 Answers
      5






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      55
      down vote



      accepted










      From the command line you can convert a notebook to python with this command:



      ipython nbconvert --to python <YourNotebook>.ipynb


      You may have to install the python mistune package:



      sudo pip install mistune





      share|improve this answer























      • This is simply the command line equivalent of @Eric correct answer.
        – ditkin
        Feb 22 '16 at 3:56






      • 7




        Subcommand ipython nbconvert is deprecated in favor of jupyter nbconvert
        – PenguinEngineer
        Nov 6 '17 at 17:33










      • I don't think this answer is correct. II realise it works but the question is how to run .ipynb from terminal, not how to convert it into a .py and then run it.
        – giac_man
        Nov 23 at 12:48















      up vote
      55
      down vote



      accepted










      From the command line you can convert a notebook to python with this command:



      ipython nbconvert --to python <YourNotebook>.ipynb


      You may have to install the python mistune package:



      sudo pip install mistune





      share|improve this answer























      • This is simply the command line equivalent of @Eric correct answer.
        – ditkin
        Feb 22 '16 at 3:56






      • 7




        Subcommand ipython nbconvert is deprecated in favor of jupyter nbconvert
        – PenguinEngineer
        Nov 6 '17 at 17:33










      • I don't think this answer is correct. II realise it works but the question is how to run .ipynb from terminal, not how to convert it into a .py and then run it.
        – giac_man
        Nov 23 at 12:48













      up vote
      55
      down vote



      accepted







      up vote
      55
      down vote



      accepted






      From the command line you can convert a notebook to python with this command:



      ipython nbconvert --to python <YourNotebook>.ipynb


      You may have to install the python mistune package:



      sudo pip install mistune





      share|improve this answer














      From the command line you can convert a notebook to python with this command:



      ipython nbconvert --to python <YourNotebook>.ipynb


      You may have to install the python mistune package:



      sudo pip install mistune






      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited Sep 8 at 12:52









      Ketul

      274




      274










      answered Feb 22 '16 at 3:48









      ditkin

      4,4372130




      4,4372130












      • This is simply the command line equivalent of @Eric correct answer.
        – ditkin
        Feb 22 '16 at 3:56






      • 7




        Subcommand ipython nbconvert is deprecated in favor of jupyter nbconvert
        – PenguinEngineer
        Nov 6 '17 at 17:33










      • I don't think this answer is correct. II realise it works but the question is how to run .ipynb from terminal, not how to convert it into a .py and then run it.
        – giac_man
        Nov 23 at 12:48


















      • This is simply the command line equivalent of @Eric correct answer.
        – ditkin
        Feb 22 '16 at 3:56






      • 7




        Subcommand ipython nbconvert is deprecated in favor of jupyter nbconvert
        – PenguinEngineer
        Nov 6 '17 at 17:33










      • I don't think this answer is correct. II realise it works but the question is how to run .ipynb from terminal, not how to convert it into a .py and then run it.
        – giac_man
        Nov 23 at 12:48
















      This is simply the command line equivalent of @Eric correct answer.
      – ditkin
      Feb 22 '16 at 3:56




      This is simply the command line equivalent of @Eric correct answer.
      – ditkin
      Feb 22 '16 at 3:56




      7




      7




      Subcommand ipython nbconvert is deprecated in favor of jupyter nbconvert
      – PenguinEngineer
      Nov 6 '17 at 17:33




      Subcommand ipython nbconvert is deprecated in favor of jupyter nbconvert
      – PenguinEngineer
      Nov 6 '17 at 17:33












      I don't think this answer is correct. II realise it works but the question is how to run .ipynb from terminal, not how to convert it into a .py and then run it.
      – giac_man
      Nov 23 at 12:48




      I don't think this answer is correct. II realise it works but the question is how to run .ipynb from terminal, not how to convert it into a .py and then run it.
      – giac_man
      Nov 23 at 12:48












      up vote
      96
      down vote













      nbconvert allows you to run notebooks with the --execute flag:



      jupyter nbconvert --execute <notebook>


      If you want to run a notebook and produce a new notebook, you can add --to notebook:



      jupyter nbconvert --execute --to notebook <notebook>


      Or if you want to replace the existing notebook with the new output:



      jupyter nbconvert --execute --to notebook --inplace <notebook>


      Since that's a really long command, you can use an alias:



      alias nbx="jupyter nbconvert --execute --to notebook"
      nbx [--inplace] <notebook>





      share|improve this answer





















      • This seems not to work behind conda virtual environment
        – Ramesh-X
        May 22 at 8:44






      • 1




        This turns the notebook into a static HTML page
        – Jim Daniël Teunis
        Sep 29 at 15:25















      up vote
      96
      down vote













      nbconvert allows you to run notebooks with the --execute flag:



      jupyter nbconvert --execute <notebook>


      If you want to run a notebook and produce a new notebook, you can add --to notebook:



      jupyter nbconvert --execute --to notebook <notebook>


      Or if you want to replace the existing notebook with the new output:



      jupyter nbconvert --execute --to notebook --inplace <notebook>


      Since that's a really long command, you can use an alias:



      alias nbx="jupyter nbconvert --execute --to notebook"
      nbx [--inplace] <notebook>





      share|improve this answer





















      • This seems not to work behind conda virtual environment
        – Ramesh-X
        May 22 at 8:44






      • 1




        This turns the notebook into a static HTML page
        – Jim Daniël Teunis
        Sep 29 at 15:25













      up vote
      96
      down vote










      up vote
      96
      down vote









      nbconvert allows you to run notebooks with the --execute flag:



      jupyter nbconvert --execute <notebook>


      If you want to run a notebook and produce a new notebook, you can add --to notebook:



      jupyter nbconvert --execute --to notebook <notebook>


      Or if you want to replace the existing notebook with the new output:



      jupyter nbconvert --execute --to notebook --inplace <notebook>


      Since that's a really long command, you can use an alias:



      alias nbx="jupyter nbconvert --execute --to notebook"
      nbx [--inplace] <notebook>





      share|improve this answer












      nbconvert allows you to run notebooks with the --execute flag:



      jupyter nbconvert --execute <notebook>


      If you want to run a notebook and produce a new notebook, you can add --to notebook:



      jupyter nbconvert --execute --to notebook <notebook>


      Or if you want to replace the existing notebook with the new output:



      jupyter nbconvert --execute --to notebook --inplace <notebook>


      Since that's a really long command, you can use an alias:



      alias nbx="jupyter nbconvert --execute --to notebook"
      nbx [--inplace] <notebook>






      share|improve this answer












      share|improve this answer



      share|improve this answer










      answered Feb 23 '16 at 8:50









      minrk

      26k57270




      26k57270












      • This seems not to work behind conda virtual environment
        – Ramesh-X
        May 22 at 8:44






      • 1




        This turns the notebook into a static HTML page
        – Jim Daniël Teunis
        Sep 29 at 15:25


















      • This seems not to work behind conda virtual environment
        – Ramesh-X
        May 22 at 8:44






      • 1




        This turns the notebook into a static HTML page
        – Jim Daniël Teunis
        Sep 29 at 15:25
















      This seems not to work behind conda virtual environment
      – Ramesh-X
      May 22 at 8:44




      This seems not to work behind conda virtual environment
      – Ramesh-X
      May 22 at 8:44




      1




      1




      This turns the notebook into a static HTML page
      – Jim Daniël Teunis
      Sep 29 at 15:25




      This turns the notebook into a static HTML page
      – Jim Daniël Teunis
      Sep 29 at 15:25










      up vote
      24
      down vote













      You can export all your code from .ipynb and save it as a .py script. Then you can run the script in your terminal.



      code export sample



      Hope it helps.






      share|improve this answer

























        up vote
        24
        down vote













        You can export all your code from .ipynb and save it as a .py script. Then you can run the script in your terminal.



        code export sample



        Hope it helps.






        share|improve this answer























          up vote
          24
          down vote










          up vote
          24
          down vote









          You can export all your code from .ipynb and save it as a .py script. Then you can run the script in your terminal.



          code export sample



          Hope it helps.






          share|improve this answer












          You can export all your code from .ipynb and save it as a .py script. Then you can run the script in your terminal.



          code export sample



          Hope it helps.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Feb 22 '16 at 3:43









          Eric

          1,352821




          1,352821






















              up vote
              4
              down vote













              For new version instead of:



              ipython nbconvert --to python <YourNotebook>.ipynb


              You can use jupyter instend of ipython:



              jupyter nbconvert --to python <YourNotebook>.ipynb





              share|improve this answer

























                up vote
                4
                down vote













                For new version instead of:



                ipython nbconvert --to python <YourNotebook>.ipynb


                You can use jupyter instend of ipython:



                jupyter nbconvert --to python <YourNotebook>.ipynb





                share|improve this answer























                  up vote
                  4
                  down vote










                  up vote
                  4
                  down vote









                  For new version instead of:



                  ipython nbconvert --to python <YourNotebook>.ipynb


                  You can use jupyter instend of ipython:



                  jupyter nbconvert --to python <YourNotebook>.ipynb





                  share|improve this answer












                  For new version instead of:



                  ipython nbconvert --to python <YourNotebook>.ipynb


                  You can use jupyter instend of ipython:



                  jupyter nbconvert --to python <YourNotebook>.ipynb






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Apr 5 at 6:19









                  Vijay Panchal

                  865




                  865






















                      up vote
                      1
                      down vote













                      Update with quoted comment by author for better visibility:




                      Author's note "This project started before Jupyter's execute API, which is now the recommended way to run notebooks from the command-line. Consider runipy deprecated and unmaintained." – Sebastian Palma




                      Install runipy library that allows running your code on terminal



                      pip install runipy


                      After just compiler your code:



                      runipy <YourNotebookName>.ipynb


                      You can try cronjob as well. All information is here






                      share|improve this answer



















                      • 7




                        Author's note "This project started before Jupyter's execute API, which is now the recommended way to run notebooks from the command-line. Consider runipy deprecated and unmaintained."
                        – Sebastian Palma
                        Mar 23 at 15:15















                      up vote
                      1
                      down vote













                      Update with quoted comment by author for better visibility:




                      Author's note "This project started before Jupyter's execute API, which is now the recommended way to run notebooks from the command-line. Consider runipy deprecated and unmaintained." – Sebastian Palma




                      Install runipy library that allows running your code on terminal



                      pip install runipy


                      After just compiler your code:



                      runipy <YourNotebookName>.ipynb


                      You can try cronjob as well. All information is here






                      share|improve this answer



















                      • 7




                        Author's note "This project started before Jupyter's execute API, which is now the recommended way to run notebooks from the command-line. Consider runipy deprecated and unmaintained."
                        – Sebastian Palma
                        Mar 23 at 15:15













                      up vote
                      1
                      down vote










                      up vote
                      1
                      down vote









                      Update with quoted comment by author for better visibility:




                      Author's note "This project started before Jupyter's execute API, which is now the recommended way to run notebooks from the command-line. Consider runipy deprecated and unmaintained." – Sebastian Palma




                      Install runipy library that allows running your code on terminal



                      pip install runipy


                      After just compiler your code:



                      runipy <YourNotebookName>.ipynb


                      You can try cronjob as well. All information is here






                      share|improve this answer














                      Update with quoted comment by author for better visibility:




                      Author's note "This project started before Jupyter's execute API, which is now the recommended way to run notebooks from the command-line. Consider runipy deprecated and unmaintained." – Sebastian Palma




                      Install runipy library that allows running your code on terminal



                      pip install runipy


                      After just compiler your code:



                      runipy <YourNotebookName>.ipynb


                      You can try cronjob as well. All information is here







                      share|improve this answer














                      share|improve this answer



                      share|improve this answer








                      edited Sep 2 at 18:30









                      Oliver Bestwalter

                      2,6972037




                      2,6972037










                      answered Feb 10 at 12:05









                      Axis

                      1,0781922




                      1,0781922








                      • 7




                        Author's note "This project started before Jupyter's execute API, which is now the recommended way to run notebooks from the command-line. Consider runipy deprecated and unmaintained."
                        – Sebastian Palma
                        Mar 23 at 15:15














                      • 7




                        Author's note "This project started before Jupyter's execute API, which is now the recommended way to run notebooks from the command-line. Consider runipy deprecated and unmaintained."
                        – Sebastian Palma
                        Mar 23 at 15:15








                      7




                      7




                      Author's note "This project started before Jupyter's execute API, which is now the recommended way to run notebooks from the command-line. Consider runipy deprecated and unmaintained."
                      – Sebastian Palma
                      Mar 23 at 15:15




                      Author's note "This project started before Jupyter's execute API, which is now the recommended way to run notebooks from the command-line. Consider runipy deprecated and unmaintained."
                      – Sebastian Palma
                      Mar 23 at 15:15


















                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • 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.





                      Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                      Please pay close attention to the following guidance:


                      • 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%2fstackoverflow.com%2fquestions%2f35545402%2fhow-to-run-an-ipynb-jupyter-notebook-from-terminal%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

                      Florida Star v. B. J. F.

                      Error while running script in elastic search , gateway timeout

                      Adding quotations to stringified JSON object values