6

I am not very familiar with python/ipython but somebody was asking me whether it is possible to start an ipython notebook with a specific python file. It then could be used for debugging. another software then would create a .py-file in the temp folder and would call an ipython notebook with this file. Is it possible or does it make sense at all?

den.run.ai
5,97318 gold badges88 silver badges146 bronze badges
asked Oct 13, 2014 at 11:15
1
  • 1
    I think what you need is to create an ipython profile, try ipython --help-all to read more what you need. Commented Oct 13, 2014 at 11:21

4 Answers 4

7

Since the question is quite broad and asking for recommendations, here are my suggestions:

  1. cross-platform nbopen, which opens ipynb using command-line or optional explorer integration:

https://github.com/takluyver/nbopen

Please note that I have one open ticket for complete Windows explorer integration:

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

[copied from github page]

Installation:

pip install nbopen

Usage:

nbopen AwesomeNotebook.ipynb
  1. run ipynb without launching the browser interface, with many useful options:

https://github.com/paulgb/runipy

[copied from github page]

Installation:

$ pip install runipy

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

$ runipy MyNotebook.ipynb

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

$ runipy -o MyNotebook.ipynb

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

$ runipy MyNotebook.ipynb OutputNotebook.ipynb

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

$ runipy MyNotebook.ipynb --html report.html
answered Apr 8, 2015 at 3:56
Sign up to request clarification or add additional context in comments.

1 Comment

runipy is unmaintained and deprecated.
4

If you're talking about launching an 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 so desire.

At my work we have one use case that does what you're saying--automatically generates a python file, then loads a new ipython server for the user to access it. However, it's a pretty special use case--for normal debugging, I would recommend just starting in iPython and not making your *.py file until the bugs are gone.

OR

If you're talking about actually automatically navigating to the page that corresponds to a python file made available by an ipython notebook server, then (1) make sure you're using ipython 2, and (2) figure out what you're desired url is (it should be deterministic) and (3) use the webbrowser module to navigate to that url.

answered Oct 13, 2014 at 12:22

5 Comments

Thank you! I'll give it a look and try to understand :-). To explain 'debugging': The application takes configured python-scripts from users which might be buggy. It would be nice if in case of an error the user can launch the ipython notebook with the python script
That sounds like a pretty cool idea to make debugging a bit more use friendly. I hope it works for you!
is this documented anywhere? I can't find any official reference on this
The command line options are documented here: jupyter-notebook.readthedocs.io/en/stable/config.html
@metaperture the first step no longer work, is there any workaround it. I have been debugging it but its not working.
1
import subprocess, os
def executeJupyter():
 env_dir = "../main_env_dir/"
 os.chdir(env_dir)
 # source jupyter_env/bin/activate
 env_activate = "jupyter_env/bin/activate_this.py"
 activate_env = exec(open(env_activate).read(), {'__file__': env_activate})
 # Open jupyter notebook as a subprocess
 openJupyter = "jupyter notebook"
 subprocess.Popen(openJupyter, shell=True)
 executeJupyter()

Make sure you change the env_dir (directory where you have the env of your jupyter notebook) and the env_activate to your own.

answered Dec 15, 2019 at 16:47

Comments

-1

To start a ipython notebook with a certain notebook directory, use the --notebook-dir command line option:

ipython notebook --notebook-dir=/Users/harold/temp/
answered Apr 7, 2015 at 20:31

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.