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?

+3


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("notebook")
sys.argv.append("--IPKernelApp.pylab='inline'")
sys.argv.append("--NotebookApp.ip=" + gethostname())
sys.argv.append("--NotebookApp.open_browser=False")
sys.argv.append("--NotebookApp.password=" + passwd())
launch_new_instance()

      

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.

OR

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.

+1


source


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:

https://github.com/takluyver/nbopen

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

https://github.com/takluyver/nbopen/issues/12

[copied from github page]

Installation:

pip install nbopen

      

Using:

nbopen AwesomeNotebook.ipynb

      

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

https://github.com/paulgb/runipy



[copied from github page]

Installation:

$ 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

      

+1


source


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

:

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

      

0


source







All Articles