Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

conda execute a Jupyter notebook #3

Open
3 tasks
pelson opened this issue Oct 17, 2015 · 6 comments
Open
3 tasks

conda execute a Jupyter notebook #3

pelson opened this issue Oct 17, 2015 · 6 comments

Comments

@pelson
Copy link
Contributor

pelson commented Oct 17, 2015

One potential approach:

  • - create a temporary environment by interpreting a part of the nbformat metadata JSON payload
  • - start a kernel using the temporary environment (ipython or otherwise)
  • - join an existing Jupyter notebookapp (or start a new one) which uses the kernel and the notebook that was passed to us

Ping @minrk / @takluyver for your wisdom. Are there any patterns I can follow? This is essentially an extension of https://github.com/takluyver/nbopen but with the addition of ensuring there is an appropriate kernel running.

@pelson
Copy link
Contributor Author

pelson commented Oct 17, 2015

Original thread came from https://twitter.com/mrocklin/status/655100657016242176

@Carreau mentioned the nbconvert --execute option.

It seems nbconvert is already in this space, the only way I would want conda-execute to add anything is if we can make use of the fact that we can define a full environment. It seems that conda execute my_analysis.ipynb could do a number of things:

  • launch the Jupyter notebook with a suitable kernel without running any of the actual code
  • run the notebook and convert to html (as nbconvert is currently doing)
  • run the notebook and save on top of the existing notebook

Rather than bake any of this in, conda-execute would essentially call out to the appropriate executable:

$ cat my_analysis.ipynb
{
  "metadata" : {
    "conda-execute": {
        "env": ['python >2', 'numpy==1.10', 'nbconvert'],
        "run_with": ["nbconvert",  "--execute"]
    },
  },
  "nbformat": 4,
  "nbformat_minor": 0,
  "cells" : [
  ...
   ]
}

Of course, to do this, conda-execute does need to read the metadata from the notebook format.

@takluyver
Copy link

I think that it would be valuable to have conda setting up environments based on notebook metadata. One way to do this might be a custom kernelspec manager which could look at metadata when a notebook is opened and construct a suitable environment at that time. I think we've talked to @ahmadia about a similar idea w/r/t hashdist.

@ahmadia
Copy link

ahmadia commented Oct 17, 2015

Hi folks. We've been trying to figure out how to do this from the conda side as well. As @takluyver mentioned, one option is to attach the conda environment directly to the notebook metadata. See the discussion here: conda-archive/conda-env#111 and the feature here: http://conda.pydata.org/docs/commands/env/conda-env-attach.html

From there, you need a corresponding launch action. One option is conda launch from @ijstokes - https://github.com/conda/conda-launch

cc: @chdoig @damianavila @pwang @malev

I'm happy to discuss here a bit more about what the various options are and what we like/dislike about each.

@ahmadia
Copy link

ahmadia commented Oct 17, 2015

Of course, anything we do for conda should be similarly applicable to HashDist. Thanks for the mention @takluyver.

@Carreau
Copy link

Carreau commented Oct 17, 2015

For nbconvert --execute you need to replace the execute preprocessor by one that start kernels in an env. Kernelspec already can have an "env" metadata so overwriting PATH, should be sufficient.

Running the notebook app in the env seem unnecessary as IIUC, you want to run the notebook kernel in the env,

run the notebook and convert to html (as nbconvert is currently doing)
run the notebook and save on top of the existing notebook

This will already be taken care of if you use --to ipynb or --to html with nbconvert.
I guess you might want to use nbconvert as a library instead of shelling out, we can figure that out.

@ahmadia
Copy link

ahmadia commented Oct 17, 2015

Running the notebook app in the env seem unnecessary as IIUC, you want to run the notebook kernel in the env,

This made sense when the kernel spec was changing rapidly and you wanted the app version to match the kernel version. I agree that this is not a hard requirement for using environments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants