[IPython-user] Problem with IPShellEmbed

Michael Foord mike at pcblokes.com
Fri Jan 28 03:29:21 CST 2005

I've encountered a problem with IPShellEmbed, for my Movable Python 
project. It's quite likely that this problem is my fault - but I would 
still appreciate help ! It looks like a frame object is expected and 
None is returned.

Basically *sometimes* a call to IPShellEmbed will fail :

ipshell = IPShellEmbed(argv, banner=banner)

The error raised occurs in :
  File "C:\Python24\Lib\site-packages\IPython\Itpl.py", line 182, in __str__
    while frame.f_globals["__name__"] == __name__: frame = frame.f_back
AttributeError: 'NoneType' object has no attribute 'f_globals'

This is intermittent and I can't work out the pattern. (Although it will 
consistently fail when I use Movable Python to open the same files...).

I've shown below the full traceback below (formatted by cgitb I'm afraid 
- I was using a CGI script as an example that caused the failure). I've 
also shown the function that calls IPShellEmbed.

Any help would be much appreciated.

(To explain the output below - Movable Python runs the script it is 
given and then calls the interactive() function. In this example the 
main script ends with a sys.exit() (which is trapped) and then 
interactive() is called. I do get the same error on some scripts that 
don't end with a sys.exit() though).

Traceback (most recent call last):
  File "F:\Temp\movpy-0.4.5-2.4-standard\movpy\movpy.py", line 431, in ?
  File "jalopy.py", line 45, in ?
  File "../jalopy\makepage.py", line 150, in main
    action, userconfig = login(theform, userdir, thisscript)       # 
this function di
splays login and exits if it fails, otherwise it prints the new/updated 
  File "../modules\login_tools\login.py", line 102, in login
    action, userconfig, newcookie = checklogin(userdir, thisscript, 
action)    # this
 function displays login and exits if there is no valid login
  File "../modules\login_tools\login.py", line 190, in checklogin
    displaylogin(userdir, thisscript, action)
  File "../modules\login_tools\login.py", line 234, in displaylogin

<!--: spam
Content-Type: text/html

<body bgcolor="#f0f0f8"><font color="#f0f0f8" size="-5"> -->
<body bgcolor="#f0f0f8"><font color="#f0f0f8" size="-5"> --> -->
</font> </font> </font> </script> </object> </blockquote> </pre>
</table> </table> </table> </table> </table> </font> </font> 
</font><pre>Traceback (m
ost recent call last):
  File "F:\Temp\movpy-0.4.5-2.4-standard\movpy\movpy.py", line 441, in ?
    interactive()       # enter the console with the current locals
  File "F:\Temp\movpy-0.4.5-2.4-standard\movpy\movpy.py", line 71, in 
    ipshell = IPShellEmbed(argv, banner=banner)
  File "C:\Python24\Lib\site-packages\IPython\Shell.py", line 133, in 
    self.IP = make_IPython(argv,rc_override=rc_override,embedded=True)
  File "C:\Python24\Lib\site-packages\IPython\ipmaker.py", line 82, in 
    IP = shell_class('__IP',user_ns=user_ns,**kw)
  File "C:\Python24\Lib\site-packages\IPython\iplib.py", line 606, in 
    self.BANNER = itpl("Python $sys.version on $sys.platform\n"
  File "C:\Python24\Lib\site-packages\IPython\Itpl.py", line 226, in itpl
    def itpl(text): return str(Itpl(text))
  File "C:\Python24\Lib\site-packages\IPython\Itpl.py", line 182, in __str__
    while frame.f_globals["__name__"] == __name__: frame = frame.f_back
AttributeError: 'NoneType' object has no attribute 'f_globals'


def interactive(localvars=None):
    """A very simple function to embed an interactive interpreter into 
    # could have the banner passed in as an optional argument, plus 
maybe the IPython config file location
    IPShellEmbed = None
        from IPython.Shell import IPShellEmbed
    except ImportError:

    if not IPShellEmbed or IPOFF:
        if localvars == None:
            localvars = sys._getframe(0).f_back.f_locals        # 
extract locals from the calling frame - taken from IPython
        from code import InteractiveConsole
        con = InteractiveConsole(localvars)
        banner = 'Movable Python\nIPython Interactive Shell. See the 
manual for a list of features and tips.\nCtrl-D to exit.'
        argv = ['-ipythondir', libdir]              # where to find the 
ipython config file
        ipshell = IPShellEmbed(argv, banner=banner)

Any more details can be supplied of course !



More information about the IPython-user mailing list