You can run another Jupyter Notebook from within a notebook using the %%bash
magic command. This command allows you to execute shell commands directly within your notebook.
Here's how you can do it:
-
Start a new cell in your notebook.
-
Type
%%bash
at the beginning of the cell. This tells Jupyter to interpret the following lines as shell commands. -
Enter the command to run your other notebook. This will typically involve using the
jupyter nbconvert
command with the--execute
flag. For example, to run a notebook namedmy_other_notebook.ipynb
, you would use the following command:jupyter nbconvert --execute my_other_notebook.ipynb
-
Run the cell. Jupyter will execute the shell command, which will run the specified notebook.
Example:
%%bash
jupyter nbconvert --execute my_other_notebook.ipynb
Important Notes:
- The notebook you are running must be in the same directory as the notebook you are currently working in or in a directory on your system's PATH.
- You can use the
--to
flag with thejupyter nbconvert
command to specify the output format of the executed notebook. For example, you can use--to html
to generate an HTML file.
This method allows you to execute other notebooks within your workflow, making it easier to manage and organize your code.