Comments (4)
I played around with this. If you can get __package__
to be 'ipynb.fs' and have ipynb.fs imported, then you can just do from .somenotebook import X
and it'll work same as from ipynb.fs.somenotebook import X
. We could possibly do this for notebooks with an ipython extension of some sort?
from ipynb.
Right now, I tested this by having two files:
wat/say.ipynb:
def say(what):
print(what)
wat/init.ipynb
from .say import say
__all__ = [say]
Now, from outside, I could do this:
from wat import say
say('hello world')
That calls the correct function, and works!
So this works from the outside. However, if I try to execute wat/init.ipynb in the notebook interface, I get the following error on import:
SystemError: Parent module '' not loaded, cannot perform relative import
if I run:
__package__ = 'ipynb.fs.wat'
before importing, it gets to:
SystemError: Parent module 'ipynb.fs.wat' not loaded, cannot perform relative import
Which is better. if I do a:
import ipynb.fs.wat
in init.ipynb it succeeds (weird!) and then if I try to relative import again I get:
ImportError: No module named 'ipynb.fs.wat.Untitled'; 'ipynb.fs.wat' is not a package
Curious and needs more investigation :D
from ipynb.
So I did a bunch of work here, and it kinda works.
In test.ipynb:
def say(what):
print(what)
In client.ipynb:
__package__ = 'ipynb.fs'
import ipynb.fs
from .test import say
say("hello world")
This works. The first two lines in the client are the boilerplate. We might be able to automate that with some ipynb extension setup maybe?
Note that this totally works when you're calling it from python directly or with python -m
.
from ipynb.
Funkier than expected. Right now, if notebook A imports notebook B as:
from ipynb.fs.full.notebookB import foo
and then notebook B imports notebook C as
import ipynb.fs
from .defs.notebookC import bar
The transient import will fail, since the package for notebookB will already be ipynb.fs.full.notebookB
.
The underlying core problem is:
- Python doesn't set package for interactive usage at all, so relative imports currently don't work in notebook at all. So we're trying to add additional semantics there, and this causes confusion.
- We want the code to work the same when imported as a module and when run interactively. These need to be accomplished via separate mechanisms, and they must be kept in sync.
It looks like we might need to do AST munging to make this happen. We just munge AST to resolve the relative imports ourselves.
from ipynb.
Related Issues (20)
- TypeError that occurs in IPython notebook but not IPython shell HOT 4
- IndentationError: unexpected indent HOT 7
- can not import functions that have doc string in them
- AttributeError: 'Tuple' object has no attribute 'id' HOT 1
- Fails on image ref in markdown
- ipynb.fs.defs raise error if there is subscript line HOT 2
- AttributeError in _filter_ast_node HOT 1
- Reload semantics HOT 3
- __package__ = None
- %matplotlib in the source notebook causes error HOT 2
- Encoding errors
- Better API ergonomics
- Import importnb to this project HOT 5
- import error
- incorrect version or language HOT 8
- How to import the ipynb file that is in a different folder HOT 2
- use symbolic link notebook
- Load ipynb contained from a different directory HOT 2
- Colab setup HOT 1
- importing .ipynb notebooks in Sagemath 9.4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ipynb.