Forums

zope.interfaces imports in ipython2.7 but not python2.7

Hello all, I'm using Pyramid, because I code in modern python but need my webapp to run in 2.7 for pythonanywhere. On my own system, everything works well enough, but when I uploaded to PA, I got "no module called 'interface'".

Upon digging, I discovered that zope.interface is used by the Configurator object in Pyramid. But, zope.interface is installed on PA, apparently at the latest version.

If I pop a 2.7 shell, I get the same importerror when I type "import zope.interface".. but bizarrely, when I do the same in ipython2.7, I have no problems.

So..what's up? :)

(edit: Title is incorrect and names zope.interfaces, rather than zope.interface. Just to clarify, that's not the bug!)

That is baffling. I confirm we can reproduce the problem.

All I can think of is, I think IPython has zope as one of its dependencies, so it may do some weird messing with sys.path, and pre-import it somehow. Look at this, for example:

11:26 ~ $  python2.7 -c"import zope; print zope.__path__"
['/usr/local/lib/python2.7/dist-packages/zope']
11:26 ~ $ ipython2.7 -c"import zope; print zope.__path__"
['/usr/local/lib/python2.7/dist-packages/zope', '/usr/lib/python2.7/dist-packages/zope']

Anyway, I tried several hacks to get it to work and couldn't get it to work.

What you can do is do a fresh install of zope.interface into a virtualenv. That works as far as I can tell. There's some info on virtualenvs here.