Giter VIP home page Giter VIP logo

import-ipynb's Introduction

Motivation

Suppose you want to import the contents of A.ipynb into B.ipynb.

Installation

pip install import-ipynb

How to use

Place both ipynb files in the same directory. Then, in the B.ipynb:

import import_ipynb
import A

Congratulations! You can now run any functions defined in A.ipynb from B.ipynb!

How it works

The code within import_ipynb.py defines a "notebook loader" that allows you to 'import' other ipynb files into your current ipynb file. This entails:

  1. load the notebook document into memory
  2. create an empty Module
  3. execute every cell in the Module namespace

Note that since every cell in the A.ipynb is executed when you import the the file, A.ipynb should only contain classes and function definitions (otherwise you'll end up loading all variables and data into memory).

Credits

The code within imoprt_ipynb.py comes from http://jupyter-notebook.readthedocs.io/en/latest/examples/Notebook/Importing%20Notebooks.html.

Riley F. Edmunds (@rileyedmunds) wrote instructions on how to use it and Lev Maximov (@axil) packaged it.

import-ipynb's People

Contributors

arnaudwald avatar axil avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

import-ipynb's Issues

it doesn't work!

import import_ipynb
import DFATPre
injest()

and I get
importing Jupyter notebook from DFATPre.ipynb

NameError Traceback (most recent call last)
in
1 import import_ipynb
2 import DFATPre
----> 3 injest()

NameError: name 'injest' is not defined

Doesn't work using Gunicorn on Heroku

I am using import-ipynb locally and it works perfectly fine, but I can't get it to work with Gunicorn on Heroku (Ubuntu 20.04).

2022-12-03T14:41:37.471070+00:00 app[web.1]: Traceback (most recent call last):
2022-12-03T14:41:37.471071+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/arbiter.py", line 589, in spawn_worker
2022-12-03T14:41:37.471071+00:00 app[web.1]: worker.init_process()
2022-12-03T14:41:37.471071+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/workers/base.py", line 134, in init_process
2022-12-03T14:41:37.471072+00:00 app[web.1]: self.load_wsgi()
2022-12-03T14:41:37.471072+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/workers/base.py", line 146, in load_wsgi
2022-12-03T14:41:37.471072+00:00 app[web.1]: self.wsgi = self.app.wsgi()
2022-12-03T14:41:37.471074+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
2022-12-03T14:41:37.471074+00:00 app[web.1]: self.callable = self.load()
2022-12-03T14:41:37.471074+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 58, in load
2022-12-03T14:41:37.471075+00:00 app[web.1]: return self.load_wsgiapp()
2022-12-03T14:41:37.471075+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 48, in load_wsgiapp
2022-12-03T14:41:37.471075+00:00 app[web.1]: return util.import_app(self.app_uri)
2022-12-03T14:41:37.471076+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/util.py", line 359, in import_app
2022-12-03T14:41:37.471076+00:00 app[web.1]: mod = importlib.import_module(module)
2022-12-03T14:41:37.471076+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/importlib/__init__.py", line 127, in import_module
2022-12-03T14:41:37.471078+00:00 app[web.1]: return _bootstrap._gcd_import(name[level:], package, level)
2022-12-03T14:41:37.471078+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
2022-12-03T14:41:37.471078+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 983, in _find_and_load
2022-12-03T14:41:37.471079+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
2022-12-03T14:41:37.471079+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
2022-12-03T14:41:37.471079+00:00 app[web.1]: File "<frozen importlib._bootstrap_external>", line 728, in exec_module
2022-12-03T14:41:37.471079+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
2022-12-03T14:41:37.471080+00:00 app[web.1]: File "/app/app.py", line 49, in <module>
2022-12-03T14:41:37.471080+00:00 app[web.1]: notebooks.run_breadth()
2022-12-03T14:41:37.471080+00:00 app[web.1]: File "/app/notebooks.py", line 4, in run_breadth
2022-12-03T14:41:37.471080+00:00 app[web.1]: from breadth import breadth
2022-12-03T14:41:37.471080+00:00 app[web.1]: ImportError: cannot import name 'breadth' from 'breadth' (/app/breadth/__init__.py)

Neat tool - dependency fix?

This is a very neat package! Would you consider adding IPhython and nbformat as requirements in the setup.py so that they get automatically set up in a fresh installation?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.