IPython Shell embedding fails after upgrade to IPython 1.0
Closed this issue · 8 comments
Hi,
I have a small internal Flask application.
Today I upgraded some packages among which Flask-Script (to version 0.6) and IPython (to the newly released 1.0 version).
When I tried to start an interactive shell via
$ ./manage.py shell
I received the following error:
Traceback (most recent call last):
File "./manage.py", line 83, in <module>
manager.run()
File "/srv/envs/intranet/local/lib/python2.7/site-packages/flask_script/__init__.py", line 366, in run
raise e
AttributeError: 'module' object has no attribute 'frontend'
After some digging around in commands.py
on line 258 I saw the following line:
sh = IPython.frontend.terminal.embed.InteractiveShellEmbed(banner1=self.banner)
I simply removed frontend
and changed the line to the following:
sh = IPython.terminal.embed.InteractiveShellEmbed(banner1=self.banner)
After that everything worked correctly.
I suppose you need to add a check for the installed version of IPython and if it is 1.0 or newer then use the new way of embedding the IPython shell or maybe simply checking if the module has a 'frontend' attribute.
E.g.
import IPython
if hasattr(IPython, 'frontend'):
sh = IPython.frontend.terminal.embed.InteractiveShellEmbed(banner1=self.banner)
else:
sh = IPython.terminal.embed.InteractiveShellEmbed(banner1=self.banner)
I just pushed an update that uses a less explicit path to the InteractiveShellEmbed. If you care to test and verify, I'll release a new version with the fix.
Maybe I am missing something but I tried installing the development version after your fix and it is not working.
The error message I receive is as follows:
AttributeError: 'function' object has no attribute 'InteractiveShellEmbed'
Maybe it is just me doing something stupid but I went ahead and checked it and IPython.embed
is a function and it has no attribute InteractiveShellEmbed
.
You can check it for yourself by installing IPython 1.0 and trying to run the following script:
import IPython
banner = 'some banner text ...'
try:
sh = IPython.Shell.IPShellEmbed(banner=banner)
except AttributeError:
sh = IPython.embed.InteractiveShellEmbed(banner1=banner)
sh(global_ns=dict(), local_ns=dict())
In this case you would receive the following error:
Traceback (most recent call last):
File "sh.py", line 8, in <module>
sh = IPython.embed.InteractiveShellEmbed(banner1=banner)
AttributeError: 'function' object has no attribute 'InteractiveShellEmbed'
But if you change it to:
import IPython
banner = 'some banner text ...'
try:
sh = IPython.Shell.IPShellEmbed(banner=banner)
except AttributeError:
sh = IPython.terminal.embed.InteractiveShellEmbed(banner1=banner)
sh(global_ns=dict(), local_ns=dict())
Note: Please notice that it now has a terminal
between IPython
and embed
, as in:
sh = IPython.terminal.embed.InteractiveShellEmbed(banner1=banner)
In this case you would see something like the following prompt:
some banner text ...
In [1]:
Maybe you can try my proposed fix in the original post of this issue:
if hasattr(IPython, 'frontend'):
sh = IPython.frontend.terminal.embed.InteractiveShellEmbed(banner1=self.banner)
else:
sh = IPython.terminal.embed.InteractiveShellEmbed(banner1=self.banner)
That's the one I added to my installation and it is working as far as I can tell.
Thanks for your time.
Can you try this, change:
sh = IPython.embed.InteractiveShellEmbed(banner1=banner)
to
sh = IPython.embed(banner1=self.banner)
I changed the line just as you suggested and it is working fine now and I do land on an IPython shell.
When I exit the shell I do receive the following error though:
TypeError Traceback (most recent call last)
/home/gledi/Projects/ama_project/sh.py in <module>()
3 sh = IPython.embed(banner1='banner')
4
----> 5 sh(global_ns=dict(), local_ns=dict())
6
TypeError: 'NoneType' object is not callable
However it doesn't matter and we don't have to waste time investigating this issue since it does not affect anything as far as I can tell.
Thanks for this extension and your prompt replies.
All the best.
Awe, that's an easy fix (embed()
is not returning a callable like InteractiveShellEmbed()
was. I'll clean that up and release an update to pypi tonight/this weekend.
I just pushed an update that should have this fixed. When you have a moment, please try it out and let me know.
That fixed the problem for me. Thanks, Sean!
I'll clean that up and release an update to pypi tonight/this weekend.
Fantastic. Do you know if there's any way to be notified when a Python package release has been pushed to PyPI? Any suggestions for that?
If not, perhaps you could post a comment here if it's not too much trouble. :^)
Pushed v0.6.1 to PyPI