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

%load_ext importnb fails if ipython is EggInfoDistribution rather than DistInfoDistribution #90

Open
waynebliu opened this issue Nov 18, 2019 · 4 comments

Comments

@waynebliu
Copy link

%load_ext importnb

ImportError Traceback (most recent call last)
in
----> 1 get_ipython().run_line_magic('load_ext', 'importnb')

/tmp/artfs-fuse-mount-7G7IIgcG/523966b89c949a780a9134439028df4a494dbca6_20191116_125724_031/glibc-2.13-x86_64/ext/public/python/ipython/7/5/0/dist/lib/python3.6/IPython/core/interactiveshell.py in run_line_magic(self, magic_name, line, _stack_depth)
2305 kwargs['local_ns'] = sys._getframe(stack_depth).f_locals
2306 with self.builtin_trap:
-> 2307 result = fn(*args, **kwargs)
2308 return result
2309

in load_ext(self, module_str)

/tmp/artfs-fuse-mount-7G7IIgcG/523966b89c949a780a9134439028df4a494dbca6_20191116_125724_031/glibc-2.13-x86_64/ext/public/python/ipython/7/5/0/dist/lib/python3.6/IPython/core/magic.py in (f, *a, **k)
185 # but it's overkill for just that one bit of state.
186 def magic_deco(arg):
--> 187 call = lambda f, *a, **k: f(*a, **k)
188
189 if callable(arg):

/tmp/artfs-fuse-mount-7G7IIgcG/523966b89c949a780a9134439028df4a494dbca6_20191116_125724_031/glibc-2.13-x86_64/ext/public/python/ipython/7/5/0/dist/lib/python3.6/IPython/core/magics/extension.py in load_ext(self, module_str)
31 if not module_str:
32 raise UsageError('Missing module name.')
---> 33 res = self.shell.extension_manager.load_extension(module_str)
34
35 if res == 'already loaded':

/tmp/artfs-fuse-mount-7G7IIgcG/523966b89c949a780a9134439028df4a494dbca6_20191116_125724_031/glibc-2.13-x86_64/ext/public/python/ipython/7/5/0/dist/lib/python3.6/IPython/core/extensions.py in load_extension(self, module_str)
85 dir=compress_user(self.ipython_extension_dir)))
86 mod = sys.modules[module_str]
---> 87 if self._call_load_ipython_extension(mod):
88 self.loaded.add(module_str)
89 else:

/tmp/artfs-fuse-mount-7G7IIgcG/523966b89c949a780a9134439028df4a494dbca6_20191116_125724_031/glibc-2.13-x86_64/ext/public/python/ipython/7/5/0/dist/lib/python3.6/IPython/core/extensions.py in _call_load_ipython_extension(self, mod)
132 def _call_load_ipython_extension(self, mod):
133 if hasattr(mod, 'load_ipython_extension'):
--> 134 mod.load_ipython_extension(self.shell)
135 return True
136

/tmp/artfs-fuse-mount-7G7IIgcG/523966b89c949a780a9134439028df4a494dbca6_20191116_125724_031/glibc-2.13-x86_64/ext/public/python/importnb/0/5/5/dist/lib/python3.6/importnb/ipython_extension.py in load_ipython_extension(ip)
96 def load_ipython_extension(ip=None):
97 global manager, module
---> 98 if IPYTHON_MAIN():
99 from .parameterize import Parameterize as Notebook
100 else:

/tmp/artfs-fuse-mount-7G7IIgcG/523966b89c949a780a9134439028df4a494dbca6_20191116_125724_031/glibc-2.13-x86_64/ext/public/python/importnb/0/5/5/dist/lib/python3.6/importnb/ipython_extension.py in IPYTHON_MAIN()
90 return (
91 getattr(runner_frame, "function", None)
---> 92 == pkg_resources.load_entry_point("ipython", "console_scripts", "ipython").name
93 )
94

/nas/local/simscripts/wayne/.nest/qcnest2/lib/python3.6/site-packages/pkg_resources/init.py in load_entry_point(dist, group, name)
478 def load_entry_point(dist, group, name):
479 """Return name entry point of group for dist or raise ImportError"""
--> 480 return get_distribution(dist).load_entry_point(group, name)
481
482

/nas/local/simscripts/wayne/.nest/qcnest2/lib/python3.6/site-packages/pkg_resources/init.py in load_entry_point(self, group, name)
2688 ep = self.get_entry_info(group, name)
2689 if ep is None:
-> 2690 raise ImportError("Entry point %r not found" % ((group, name),))
2691 return ep.load()
2692

ImportError: Entry point ('console_scripts', 'ipython') not found

import pkg_resources
type(pkg_resources.get_distribution('ipython'))

pkg_resources.EggInfoDistribution

@waynebliu
Copy link
Author

I think a simple solution is to wrap try/except around the if IPYTHON_MAIN() line

@waynebliu
Copy link
Author

Would be nice to have this in 0.5.6 if possible...

@tonyfast
Copy link
Member

tonyfast commented Dec 6, 2019

I'm sorry I delayed answering this.

Could you post a line of code/pr that shows the fix you used?

@waynebliu
Copy link
Author

Ugly workaround: I create my wrapper extension and just catch the exception

def load_ipython_extension(ip=None):
import importnb, importnb.ipython_extension
try:
if importnb.ipython_extension.IPYTHON_MAIN():
from importnb.parameterize import Parameterize as Notebook
else:
from importnb.loader import Notebook
except:
from importnb.loader import Notebook
... # rest is same

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

2 participants