Start ipython notebook with python file

I'm not very familiar with python / ipython, but someone asked me if it is possible to run an ipython notebook with a specific python file. It can then be used for debugging. other software would then create a .py file in the temp folder and would call ipython notebook with that file. Is this possible or does it make sense at all?


source to share

3 answers

If you are talking about running iPython notebook server via Python, I use this:

#!/usr/bin/env python
from IPython.terminal.ipapp import launch_new_instance
from IPython.lib import passwd
from socket import gethostname
import warnings
warnings.filterwarnings("ignore", module = "zmq.*")
sys.argv.append("--NotebookApp.ip=" + gethostname())
sys.argv.append("--NotebookApp.password=" + passwd())


Obviously, you can change the arguments if you like.

In my work we use one case that does what you say - automatically generates a python file and then loads a new ipython server for the user to access it. However, this is a pretty special use case - for normal debugging, I would recommend just starting with iPython and not making your * .py file until the errors are gone.


If you say that you actually automatically go to the page that matches the python file available for the ipython portable server, then (1) make sure you are using ipython 2, and (2) figure out that you are "Required url ( it must be deterministic) and (3) use a web browser plug- in to navigate to that url.



Since the question is rather broad and requires guidance, here are my suggestions:

  • cross platform nbopen which opens ipynb using command line or optional explorer integration:

Note that I have one open ticket to fully integrate Windows Explorer:

[copied from github page]


pip install nbopen



nbopen AwesomeNotebook.ipynb


  1. start ipynb without launching browser interface with many useful options:

[copied from github page]


$ pip install runipy


To run the .ipynb file as a script, run:

$ runipy MyNotebook.ipynb


To save the output of each cell back to your notebook file, run:

$ runipy -o MyNotebook.ipynb


To save the laptop output as a new laptop, run:

$ runipy MyNotebook.ipynb OutputNotebook.ipynb


To run the .ipynb file and generate an HTML report, run:

$ runipy MyNotebook.ipynb --html report.html




To start ipython notebook with a specific notebook directory use the command line option --notebook-dir


ipython notebook --notebook-dir=/Users/harold/temp/




All Articles