importnb
importnb copied to clipboard
%load_ext importnb fails if ipython is EggInfoDistribution rather than DistInfoDistribution
%load_ext importnb
ImportError Traceback (most recent call last)
/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
/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
/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
I think a simple solution is to wrap try/except around the if IPYTHON_MAIN() line
Would be nice to have this in 0.5.6 if possible...
I'm sorry I delayed answering this.
Could you post a line of code/pr that shows the fix you used?
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