Error running web2py shell with IPython 0.11

200 views
Skip to first unread message

dkuhlman

unread,
Aug 17, 2011, 4:38:56 PM8/17/11
to web2py-users
The interface to the embedded shell in IPython has apparently
changed. When I do:

$ ./web2py -S myapp

I get this message:

WARNING:web2py:import IPython error; use default python shell

Here is a patch. It seems to work, but I'll admit that I'm not too
sure that it does everything that it should. Or, is there some other
place where I should post this?

# ==================================================================
--- shell.py.orig 2011-08-17 13:27:33.888019538 -0700
+++ shell.py 2011-08-17 13:25:07.778019604 -0700
@@ -216,12 +216,9 @@
'import bpython error; trying ipython...')
else:
try:
- import IPython
- # following 2 lines fix a problem with IPython;
thanks Michael Toomim
- if '__builtins__' in _env:
- del _env['__builtins__']
- shell = IPython.Shell.IPShell(argv=[],
user_ns=_env)
- shell.mainloop()
+ from IPython.frontend.terminal.embed import
InteractiveShellEmbed
+ shell = InteractiveShellEmbed(user_ns=_env)
+ shell()
return
except:
logger.warning(
# ==================================================================

- Dave

Massimo Di Pierro

unread,
Aug 17, 2011, 5:27:34 PM8/17/11
to web2py-users
In trunk. Thanks.

Carlos

unread,
Aug 18, 2011, 10:50:28 AM8/18/11
to web...@googlegroups.com
Hi Massimo,

After loading this change, my IPython shell has disappeared, leaving me with the simple python shell instead, when doing [ python web2py.py -S myapp -M -N ] in DOS on win7.

Should this change be reverted?.

Thanks,

   Carlos

Massimo Di Pierro

unread,
Aug 18, 2011, 1:17:22 PM8/18/11
to web2py-users
Do you get an error? Can you coordinate with Dave a patch that works
for both?

Carlos

unread,
Aug 18, 2011, 3:55:22 PM8/18/11
to web...@googlegroups.com
Hi,

I get the following:

C:\web2py>python web2py.py -S myapp -M -N
web2py Web Framework
Created by Massimo Di Pierro, Copyright 2007-2011
Version 1.98.2 (2011-08-18 05:41:57)
Database drivers available: SQLite3, pymysql, PostgreSQL
WARNING:web2py:import IPython error; use default python shell
Python 2.6.4 (r264:75708, Oct 26 2009, 08:23:19) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>>

Thanks,

   Carlos

dkuhlman

unread,
Aug 18, 2011, 6:56:55 PM8/18/11
to web2py-users
On Aug 18, 12:55 pm, Carlos <carlosgali...@gmail.com> wrote:
> Hi,
>
> I get the following:
>
> C:\web2py>python web2py.py -S myapp -M -N
> web2py Web Framework
> Created by Massimo Di Pierro, Copyright 2007-2011
> Version 1.98.2 (2011-08-18 05:41:57)
> Database drivers available: SQLite3, pymysql, PostgreSQL
> *WARNING:web2py:import IPython error; use default python shell*
> Python 2.6.4 (r264:75708, Oct 26 2009, 08:23:19) [MSC v.1500 32 bit (Intel)]
> on win32
> Type "help", "copyright", "credits" or "license" for more information.
> (InteractiveConsole)
>
>

So, if we want it to work for both new and older versions of IPython,
we could use the following:

#
==================================================================================
try:
import IPython
if IPython.__version__ >= '0.11':
from IPython.frontend.terminal.embed import
InteractiveShellEmbed
shell = InteractiveShellEmbed(user_ns=_env)
shell()
return
else:
# following 2 lines fix a problem with
IPython; thanks Michael Toomim
if '__builtins__' in _env:
del _env['__builtins__']
shell = IPython.Shell.IPShell(argv=[],
user_ns=_env)
shell.mainloop()
return
except:
logger.warning(
'import IPython error; use default python
shell')
#
==================================================================================

I'm a little uncomfortable doing a compare greater than or equal on
a string, but it seems to work.

An alternative is to require IPython version 0.11 or later, but
I suppose that is a bit severe.

- Dave

Massimo Di Pierro

unread,
Aug 18, 2011, 7:43:53 PM8/18/11
to web2py-users
done. thanks

Carlos

unread,
Aug 18, 2011, 8:03:15 PM8/18/11
to web...@googlegroups.com
Just to confirm, it's now working ok again - thanks!
Reply all
Reply to author
Forward
0 new messages