Search code examples
pythonjsoncherrypy

Cherrypy json_out module error in Ubuntu


I am trying to get Cherrypy to output json for a project and on my Mac adding the @cherrpy.tools.json_out() decorator is working a treat but on my Ubuntu 13.04 system I get this error.

Traceback (most recent call last):
  File "cherrypy.py", line 1, in <module>
    import cherrypy
  File "/bla/cherrypy.py", line 4, in <module>
    class Root(object):
  File "/bla/cherrypy.py", line 6, in Root
    @cherrypy.tools.json_out()
AttributeError: 'module' object has no attribute 'tools'

The code above is a direct copy from the bottom of this page. http://tools.cherrypy.org/wiki/JSON

If i enter a python shell then run interactive help on the module I get a similar result.

help> cherrypy
problem in cherrypy - <type 'exceptions.AttributeError'>: 'module' object has no attribute 'tools'

I have tried searching but I can't find anyone else having the same issue? (Maybe I am missing the wood for the trees?)

I have tried reinstalling the package through apt and manually from the cherrypy source all against Python 2.7

Although I am developing on Mac and Ubuntu I will be deploying on an Ubuntu server so I would like to sort this out sooner rather than later.

Your help is much appreciated


Solution

  • Do you use python-cherrypy from ubuntu package? It's version is 2.3.0 which does not have cherrypy.tools modules.

    Install newer version (sudo pip install -U cherrypy).